package org.jeecgframework.web.controller;

import org.apache.log4j.Logger;
import org.hibernate.criterion.Restrictions;
import org.jeecgframework.core.common.controller.BaseController;
import org.jeecgframework.core.common.exception.BusinessException;
import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
import org.jeecgframework.core.common.model.json.AjaxJson;
import org.jeecgframework.core.common.model.json.DataGrid;
import org.jeecgframework.core.constant.Globals;
import org.jeecgframework.core.util.*;
import org.jeecgframework.tag.core.easyui.TagUtil;
import org.jeecgframework.web.service.*;
import org.jeecgframework.web.system.pojo.base.*;
import org.jeecgframework.web.system.service.SystemService;
import org.jeecgframework.web.system.service.UserService;
import org.jeecgframework.web.util.FileBean;
import org.jeecgframework.web.util.StaticValue;
import org.jeecgframework.web.util.UploadFileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.util.*;


/**
 * @author onlineGenerator
 * @version V1.0
 * @Title: Controller
 * @Description: 巡检计划
 * @date 2016-03-30 11:29:40
 */
@Scope("prototype")
@Controller
@RequestMapping("/zyInspectionPlanController")
public class ZyInspectionPlanController extends BaseController {
    /**
     * Logger for this class
     */
    private static final Logger logger = Logger.getLogger ( ZyInspectionPlanController.class ); // NOPMD by dzqThinkpad on 16-4-1 下午3:02

    @Autowired
    private ZyInspectionPlanServiceI zyInspectionPlanService;
    @Autowired
    private SystemService systemService;
    @Autowired
    private ZyCommonService zyCommonService;
    @Autowired
    private ZyWorkFlowService zyWorkFlowService;
    @Autowired
    private ZyPlanRecordServiceI zyPlanRecordService;
    @Autowired
    private ZyEquipmentTypeServiceI zyEquipmentTypeService;
    @Autowired
    private CbsInspectionEvaluateServiceI cbsInspectionEvaluateServiceI;
    @Autowired
    private ZyInspectionReportServiceI zyInspectionReportServiceI;
    @Autowired
    private UserService userService;

    private String message;

    @Autowired
    private ZyTimeTaskForInstallRecordSevice zyTimeTaskForInstallRecordSevice;

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }


    /**
     * @author xiul
     * 2016-3-30 上午11:40:30
     * Description 生成巡检计划 列表页 跳转
     */
    @RequestMapping(params = "zyGenerateInspectionPlan")
    public ModelAndView zyGenerateInspectionPlan(HttpServletRequest request) {
        request.setAttribute ( "esSeverState", StaticValue.DIC_SERVER_STATE_1001 );
        return new ModelAndView ( "com/zybk/zy_inspection_plan/zyGenerateInspectionPlanList" );
    }

    /**
     * @author xiul
     * 2016-3-30 上午11:40:05
     * Description 生成巡检计划 列表页  datagrid
     */
    @RequestMapping(params = "generateInspectionPlandatagrid")
    public void generateInspectionPlandatagrid(ZyEquipmentSpareEntity zyEquipmentSpare, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
        CriteriaQuery cq = new CriteriaQuery ( ZyEquipmentSpareEntity.class, dataGrid );
        //查询条件组装器
        Map<String, String[]> paramMap = request.getParameterMap ();
        org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql ( cq, zyEquipmentSpare, paramMap );
        Calendar cal = Calendar.getInstance ();
        int year = cal.get ( Calendar.YEAR );
        for (String key : paramMap.keySet ()) {
            if (key.equals ( "hadThisYearIp" ) && !paramMap.get ( key )[0].equals ( "" )) {//是否有本年度巡检计划
//				cq.or(Restrictions.eq("isHadInspection", paramMap.get(key)[0]), Restrictions.isNull("isHadInspection"));//这里应该不加 isnull
                cq.add ( Restrictions.eq ( "isHadInspection", paramMap.get ( key )[0] ) );
                if (paramMap.get ( key )[0].equals ( "1" )) {
                    String sql = "SELECT es.id FROM zy_inspection_plan ip LEFT JOIN zy_equipment_spare es ON es.id = ip.equipment_spare_id WHERE ip.create_date BETWEEN '" + year + "-01-01' AND '" + year + "-12-31'";
                    List<Map<String, Object>> mapList = systemService.findForJdbc ( sql );
                    List<String> idsList = new ArrayList<String> ();
                    for (Map<String, Object> map : mapList) {
                        idsList.add ( map.get ( "id" ) != null ? map.get ( "id" ).toString () : "" );
                    }
                    if (idsList.size () == 0) {
                        idsList.add ( "" );
                    }
                    cq.add ( Restrictions.in ( "id", idsList ) );
                }
                continue;
            }
            if (key.equals ( "inThisYearInsScope" )) {//是否在本年度默认巡检范围内
                Date currYearFirstDay = DateUtils.str2Date ( year + "-01-01", DateUtils.date_sdf );
                if (!paramMap.get ( key )[0].equals ( "" ) && paramMap.get ( key )[0].equals ( "1" )) {//是,保修截止日期 大于等于 本年1月1日，安装日期 小于 本年1月1日
                    cq.add ( Restrictions.lt ( "installDate", currYearFirstDay ) );
                    cq.add ( Restrictions.ge ( "repairEndDate", currYearFirstDay ) );
                    continue;
                } else if (!paramMap.get ( key )[0].equals ( "" ) && paramMap.get ( key )[0].equals ( "0" )) {//否
                    cq.add (
                            Restrictions.or (
                                    Restrictions.and (//安装日期 大于等于 本年1月1日, 保修截止日期 小于 本年1月1日
                                            Restrictions.ge ( "installDate", currYearFirstDay ), Restrictions.lt ( "repairEndDate", currYearFirstDay )
                                    ),
                                    Restrictions.and (//安装日期 小于 本年1月1日, 保修截止日期 小于等于 本年1月1日
                                            Restrictions.lt ( "installDate", currYearFirstDay ), Restrictions.le ( "repairEndDate", currYearFirstDay )
                                    ),
                                    Restrictions.and (//安装日期 大于等于 本年1月1日, 保修截止日期 大于 本年1月1日
                                            Restrictions.ge ( "installDate", currYearFirstDay ), Restrictions.gt ( "repairEndDate", currYearFirstDay )
                                    )
                            )
                    );
                    continue;
                }
            }
        }

        try {
            //查询设备
            cq.add ( Restrictions.eq ( "isSpare", false ) );
        } catch (Exception e) {
            throw new BusinessException ( e.getMessage () );
        }
        cq.add ();
        this.zyInspectionPlanService.getDataGridReturn ( cq, true );

        TagUtil.datagrid ( response, dataGrid );
    }

    /**
     * @author xiul
     * 2016-6-23 下午2:40:13
     * Description 生成巡检计划之前检查设备是否可以生成巡检计划
     */
    @ResponseBody
    @RequestMapping(params = "checkEsServerState")
    public AjaxJson checkEsServerState(@RequestParam(value = "equipmentIds") String equipmentIds) {
        AjaxJson j = new AjaxJson ();
        try {
            for (String id : equipmentIds.split ( "," )) {
                if (StringUtil.isNotEmpty ( id )) {
                    ZyEquipmentSpareEntity es = systemService.getEntity ( ZyEquipmentSpareEntity.class, id );
                    if (!es.getServerState ().equals ( StaticValue.DIC_SERVER_STATE_1001 )) {
                        j.setSuccess ( false );
                        j.setMsg ( "所选设备中包含不能生成巡检计划的设备" );
                        break;
                    } else if (es.getResidualIpCount () != null && es.getResidualIpCount () == 0) {
                        j.setSuccess ( false );
                        j.setMsg ( "所选设备中包含不能生成巡检计划的设备" );
                        break;
                    }
                }
            }
        } catch (Exception e) {
            j.setSuccess ( false );
            j.setMsg ( "检查异常" );
            e.printStackTrace ();
        }
        return j;
    }

    /**
     * @param equipmentIds 设备ID
     * @param request
     * @return
     * @author xiul
     * 2016-3-30 下午2:12:03
     * Description 生成巡检计划/批量生成巡检计划 页面跳转
     */
    @RequestMapping(params = "goBatchGeneratePlan")
    public ModelAndView goBatchGeneratePlan(String equipmentIds, HttpServletRequest request) {
        /**
         * update 2016-08-26 xiul 配合修改批量生成 传参过长
         */
        Calendar cal = Calendar.getInstance ();
        int currMonth = cal.get ( Calendar.MONTH ) + 1;
        request.setAttribute ( "currMonth", currMonth );
        String view = "";
        int esLength = oConvertUtils.getInt ( request.getParameter ( "esLength" ) );
        if (esLength != 0) {
            if (esLength == 1) {
                //单独生成
                String[] equipmentIdsArr = equipmentIds.split ( "," );
                view = "com/zybk/zy_inspection_plan/zyGeneratePlan";
                if (StringUtil.isNotEmpty ( equipmentIdsArr[0] )) {
                    ZyEquipmentSpareEntity zyEquipmentSpare = systemService.get ( ZyEquipmentSpareEntity.class, equipmentIdsArr[0].toString () );
                    request.setAttribute ( "zyEquipmentSparePage", zyEquipmentSpare );
                    request.setAttribute ( "parentId", oConvertUtils.getString ( request.getParameter ( "parentId" ) ) );//标示 是否为创建子单 如果有值则为创建子单
                }
            } else if (esLength > 1) {
                //批量生成
                view = "com/zybk/zy_inspection_plan/zyBatchGeneratePlan";
                //request.setAttribute("equipmentIds", equipmentIds);
            }
            List<TSDepart> tsDeparts = zyCommonService.queryOrgByOrgTypeAndBusScope ( StaticValue.DIC_ORG_TYPE_THIRD_PARTY, StaticValue.DIC_BUS_SCOPE_INSPECTION );
            request.setAttribute ( "tsDeparts", tsDeparts );
        }
        return new ModelAndView ( view );
    }

    /**
     * @param request
     * @return
     * @author xiul
     * 2016-3-30 下午4:53:44
     * Description 新建巡检计划页 选择巡检负责人弹出页
     */
    @RequestMapping(params = "zyChooseContactersList")
    public ModelAndView zyChooseContactersList(HttpServletRequest request, String company) {
        request.setAttribute ( "company", "&roleCode=" + company );
        return new ModelAndView ( "com/zybk/zy_inspection_plan/zyChooseContactersList" );
    }
//
//	/**
//	 * @author xiul
//	 * 2016-3-30 下午4:58:05
//	 * Description  新建巡检计划页 选择巡检负责人弹出页 datagrid
//	 * @param zyContacter
//	 * @param request
//	 * @param response
//	 * @param dataGrid
//	 * @param roleCode 页面选择的巡检单位值
//	 */
//	@RequestMapping(params = "chooseContactersDatagrid")
//	public void chooseContactersDatagrid(ZyContactsEntity zyContacter,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid,
//			String roleCode) {
//		try{
//			List<Map<String, Object>> results = zyInspectionPlanService.queryDatagridResultForChooseContacters(request,roleCode);
//			dataGrid.setResults(results);
//		}catch (Exception e) {
//			throw new BusinessException(e.getMessage());
//		}
//		TagUtil.datagrid(response, dataGrid);
//	}

    /**
     * @author xiul
     * 2016-4-26 上午10:18:42
     * Description 生成巡检计划
     */
    @ResponseBody
    @RequestMapping(params = "doAdd")
    public AjaxJson doAdd(ZyInspectionPlanEntity zyInspectionPlan, HttpServletRequest request,
                          @RequestParam(value = "equipmentIds", defaultValue = "") String equipmentIds,
                          @RequestParam(value = "zyIpId", defaultValue = "") String zyIpId,
                          @RequestParam(value = "parentId", defaultValue = "") String parentId) {
        AjaxJson j = new AjaxJson ();
        message = "巡检计划添加成功";
        try {
            zyInspectionPlanService.batchGeneratePlan ( zyInspectionPlan, equipmentIds, parentId, zyIpId );
        } catch (Exception e) {
            e.printStackTrace ();
            message = "巡检计划添加失败";
            throw new BusinessException ( e.getMessage () );
        }
        systemService.addLog ( message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO );
        j.setMsg ( message );
        return j;
    }

    /**
     * @author xiul
     * 2016-4-1 下午4:10:46
     * Description 流程 - 巴可商务主管待分配巡检计划 列表页
     */
    @RequestMapping(params = "sendInspectionPlanList")
    public ModelAndView sendInspectionPlanList(HttpServletRequest request) {
//        String optRule = StaticValue.DIC_PLAN_STATE_TODO + ",";
//        optRule += StaticValue.DIC_PLAN_STATE_THIRDPARTY_REFUSED;
//        request.setAttribute ( "optRule", optRule );
        String optRule = StaticValue.DIC_PLAN_STATE_TODO ;
        request.setAttribute ( "optRule", optRule );
        return new ModelAndView ( "com/zybk/zy_inspection_plan/zySendInspectionPlanList" );
    }

    /**
     * @author xiul
     * 2016-4-1 下午5:07:29
     * Description	流程 - 巴可商务主管待分配巡检计划 列表
     */
    @RequestMapping(params = "datagridOfSendPlanList")
    public void datagridOfSendPlanList(ZyInspectionPlanEntity zyInspectionPlan, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
        //zyInspectionPlanService.queryDataGridOfSendPlanList(request,dataGrid);
        CriteriaQuery cq = new CriteriaQuery ( ZyInspectionPlanEntity.class, dataGrid );
        String state1 = request.getParameter("state1");
        Map<String, String[]> paramMap = request.getParameterMap ();
        //查询条件组装器
        org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql ( cq, zyInspectionPlan, paramMap );
        try {
            boolean flag = false; //页面查询条件是否不为空
            //巴可主管 可以查看到所有的巡检计划 所以只需要从巡检计划表查询所有 ，不需要加流程的过滤
            for (String key : paramMap.keySet ()) {
                if (   key.equals("planId") || key.equals("equipmentSpare.sn") ||
                        key.equals("equipmentSpare.bpNo") || key.equals("equipmentSpare.zyCinema.name") ||
                        key.equals("equipmentSpare.tsTerritory.territoryName") || key.equals("company") ||
                        key.equals("ipPlanDate_begin") || key.equals("ipPlanDate_end") ||
                        key.equals("reportCommitTime_begin") || key.equals("reportCommitTime_end")) {
                    if (!StringUtil.isEmpty(paramMap.get(key)[0])) {
                        flag = true;//除状态之外有查询条件
                    }
                }
                
                //因为生成巡检计划那里设置的ipPlanDate 的日 全部为 01 所以当只查询 一个月份的时候 起止时间都是 01 即可
                if (key.equals ( "ipPlanDate_begin" ) && !paramMap.get ( key )[0].equals ( "" )) {
                    cq.add ( Restrictions.ge ( "ipPlanDate", DateUtils.str2Date ( paramMap.get ( key )[0] + "-01", DateUtils.date_sdf ) ) );
                }
                if (key.equals ( "ipPlanDate_end" ) && !paramMap.get ( key )[0].equals ( "" )) {
                    cq.add ( Restrictions.le ( "ipPlanDate", DateUtils.str2Date ( paramMap.get ( key )[0] + "-01", DateUtils.date_sdf ) ) );
                }
            }

            if(StringUtil.isNotEmpty(state1)){
                String[] statuSplit = state1.split(",");
                cq.add(Restrictions.in("state", statuSplit));
            } else {
            	//除状态之外没有条件，则只查询待处理的
            	if (!flag) {
            		String[] statuSplit = StaticValue.DIC_PLAN_STATE_TODO.split(",");
            		 cq.add(Restrictions.in("state", statuSplit));
            	}
            }
            
            cq.add ();
            this.zyInspectionPlanService.getDataGridReturn ( cq, true );
            for (ZyInspectionPlanEntity zyIp : (List<ZyInspectionPlanEntity>) dataGrid.getResults ()) {
                if (zyIp != null) {
                    //设置省市 同时 显示
                    String tsTerritoryVal = "";
                    if (zyIp.getEquipmentSpare ().getTsTerritory () != null && null != zyIp.getEquipmentSpare ().getTsTerritory ().getTSTerritory ()) {
                        tsTerritoryVal = zyIp.getEquipmentSpare ().getTsTerritory ().getTSTerritory ().getTerritoryName () + "," + zyIp.getEquipmentSpare ().getTsTerritory ().getTerritoryName ();
                    } else if (zyIp.getEquipmentSpare ().getTsTerritory () != null) {
                        tsTerritoryVal = zyIp.getEquipmentSpare ().getTsTerritory ().getTerritoryName ();
                    }
                    zyIp.setTsTerritoryVal ( tsTerritoryVal );
                }
            }
        } catch (Exception e) {
            throw new BusinessException ( e.getMessage () );
        }
        TagUtil.datagrid ( response, dataGrid );
    }

    /**
     * @return
     * @author xiul
     * 2016-4-25 下午2:24:04
     * Description 流程 - 巴可的用户 - 查看 - 巡检计划详情页
     */
    @RequestMapping(params = "detailsOfPlan")
    public ModelAndView detailsOfPlan(HttpServletRequest request) {
        String id = oConvertUtils.getString ( request.getParameter ( "id" ) );
        ZyInspectionPlanEntity zyIP = zyInspectionPlanService.get ( ZyInspectionPlanEntity.class, id );
        if (null != zyIP.getIpPlanDate ()) {
            Calendar cal = Calendar.getInstance ();
            cal.setTime ( zyIP.getIpPlanDate () );
            zyIP.setIpMonth ( cal.get ( Calendar.MONTH ) + 1 + "" );//因为 ipMonth不是数据库字段，这里需要根据计划巡检日期 算出来 计划巡检月份
        }
        request.setAttribute ( "zyIP", zyIP );
        //按钮 取消 巡检计划 的 过滤条件
        List<String> btnCancelPlanRules = new ArrayList<String> ();
        btnCancelPlanRules.add ( StaticValue.DIC_PLAN_STATE_TODO );
        btnCancelPlanRules.add ( StaticValue.DIC_PLAN_STATE_SEND_TO_THIRDPARTY );
        btnCancelPlanRules.add ( StaticValue.DIC_PLAN_STATE_THIRDPARTY_REFUSED );
        btnCancelPlanRules.add ( StaticValue.DIC_PLAN_STATE_THIRDPARTY_ASSIGNED );
        btnCancelPlanRules.add ( StaticValue.DIC_PLAN_STATE_AREA_ENGINEER_REFUSED );
        btnCancelPlanRules.add ( StaticValue.DIC_PLAN_STATE_AREA_ENGINEER_ASSIGNED );
        btnCancelPlanRules.add ( StaticValue.DIC_PLAN_STATE_ENGINEER_REFUSED );
        btnCancelPlanRules.add ( StaticValue.DIC_PLAN_STATE_ENGINEER_ASSIGNED );
        btnCancelPlanRules.add ( StaticValue.DIC_PLAN_STATE_ENGINEER_IN_IMPLEMENT );
        boolean btnCanCancel = false;
        if (btnCancelPlanRules.contains ( zyIP.getState () )) {
            btnCanCancel = true;
        }
        request.setAttribute ( "btnCanCancel", btnCanCancel );
        //巡检单位
        List<TSDepart> tsDeparts = zyCommonService.queryOrgByOrgTypeAndBusScope ( StaticValue.DIC_ORG_TYPE_THIRD_PARTY, StaticValue.DIC_BUS_SCOPE_INSPECTION );
        request.setAttribute ( "tsDeparts", tsDeparts );
        Calendar cal = Calendar.getInstance ();
        int currMonth = cal.get ( Calendar.MONTH ) + 1;
        request.setAttribute ( "currMonth", currMonth );
//        18年1月15号 bingyue 第三方拒绝的任务，不能再进行操作，只能关单
//        if (zyIP.getState ().equals ( StaticValue.DIC_PLAN_STATE_THIRDPARTY_REFUSED )) {//如果是第三方拒绝了任务。这里可以重新指派，所以跳转到分配页面，其中也可以取消巡检计划
//            ZyEquipmentSpareEntity zyEquipmentSpare = zyIP.getEquipmentSpare ();
//            request.setAttribute ( "zyEquipmentSparePage", zyEquipmentSpare );
//            return new ModelAndView ( "com/zybk/zy_inspection_plan/zyGeneratePlan" );
//        }
        TSType tsType = zyCommonService.queryTsType ( StaticValue.DIC_PLAN_STATE, zyIP.getState () );
        zyIP.setStateVal ( null != tsType ? tsType.getTypename () : "" );
        //设备单拿出来
        request.setAttribute ( "zyES", zyIP.getEquipmentSpare () );
        //巡检流程 进度
        request.setAttribute ( "planStateProcessBeans", zyPlanRecordService.queryPlanStateProcess ( zyIP.getId () ) );
        //影院巡检联系人单查
        String cinemaId = zyIP.getEquipmentSpare ().getZyCinema () != null ? zyIP.getEquipmentSpare ().getZyCinema ().getId () : "";
        ZyContactsEntity zyContact = zyInspectionPlanService.queryCinemaInspectionContact ( cinemaId );
        request.setAttribute ( "zyContact", zyContact );
        //银幕类型 取字典对应值
        if (null != zyIP.getEquipmentSpare ().getHouse ()) {
            TSType screenType = zyCommonService.queryTsType ( StaticValue.DIC_SCREEN_TYPE, zyIP.getEquipmentSpare ().getHouse ().getScreenType () );
            request.setAttribute ( "screenType", null != screenType ? screenType.getTypename () : "" );
        }
        request.setAttribute ( "btnSaveRules", StaticValue.DIC_PLAN_STATE_TODO );
        request.setAttribute ( "btnChildRules", StaticValue.DIC_PLAN_STATE_INSPECTION_COMPLETE );//只有已完成的巡检计划才可以创建子单
        //影院技术主管
        List<ZyContactsEntity> cinemaContacts =
                systemService.findHql ( "from ZyContactsEntity where belongCinema.id =? and position =? and state = ? and isDelete = ?",
                        null != zyIP.getEquipmentSpare ().getZyCinema () ? zyIP.getEquipmentSpare ().getZyCinema ().getId () : "", StaticValue.DIC_CONTACT_POSITION_C_TECHNICAL_DIRECTOR, StaticValue.DIC_ENGINEER_STATE_ONJOB, "0" );
        request.setAttribute ( "cmContactTechnicalDirector", cinemaContacts != null && cinemaContacts.size () > 0 ? cinemaContacts.get ( 0 ) : "" );
        //是否显示 按钮查看巡检报告和修改巡检报告 标示
        request.setAttribute ( "viewOrUpdateReportFlag", zyInspectionPlanService.judgeViewOrUpdateReport ( zyIP.getId () ) );
        return new ModelAndView ( "com/zybk/zy_inspection_plan/zyInspectionPlanDetials" );
    }

    /**
     * @author xiul
     * 2016-6-27 下午8:53:47
     * Description 跳转取消巡检计划页面
     */
    @RequestMapping(params = "goCancelIP")
    public ModelAndView goCancelIP(HttpServletRequest request) {
        request.setAttribute ( "id", request.getParameter ( "id" ) );
        return new ModelAndView ( "com/zybk/zy_inspection_plan/zyCancelIP" );
    }

    /**
     * @param zyInspectionPlan
     * @param request
     * @param operationType    操作类型
     * @author xiul
     * 2016-4-26 上午11:01:21
     * Description 巴可 查看巡检计划页 操作巡检计划
     */
    @RequestMapping(params = "doUpdate")
    @ResponseBody
    public AjaxJson doUpdate(ZyInspectionPlanEntity zyInspectionPlan, HttpServletRequest request) {
        AjaxJson j = new AjaxJson ();
        ZyInspectionPlanEntity t = zyInspectionPlanService.get ( ZyInspectionPlanEntity.class, zyInspectionPlan.getId () );
        try {
            String oprationType = oConvertUtils.getString ( request.getParameter ( "operationType" ) );
            if (oprationType.equals ( StaticValue.DIC_PLAN_OPERATION_TYPE_CANCEL )) {
                //取消巡检计划
                zyInspectionPlanService.cancelInspectionPlan ( t, request );
                message = "取消巡检计划[" + t.getPlanId () + "]成功";
            } else if (oprationType.equals ( StaticValue.DIC_PLAN_OPERATION_TYPE_UPDATE )) {
                //更新巡检计划
                String ipMonth = zyInspectionPlan.getIpMonth ();
                zyInspectionPlan.setPlanQuarter ( zyInspectionPlanService.getIpQuarterByMonth ( ipMonth ) );//保留巡检季度，根据巡检月份计算
                Calendar cal = Calendar.getInstance ();
                cal.setTime ( t.getIpPlanDate () );
                int year = cal.get ( Calendar.YEAR );
                zyInspectionPlan.setIpPlanDate ( DateUtils.str2Date ( year + "-" + ipMonth + "-01", DateUtils.date_sdf ) );
                MyBeanUtils.copyBeanNotNull2Bean ( zyInspectionPlan, t );
                zyInspectionPlanService.saveOrUpdate ( t );
                message = "更新巡检计划[" + t.getPlanId () + "]成功";
            }
        } catch (Exception e) {
            e.printStackTrace ();
            message = "操作巡检计划[" + t.getPlanId () + "]失败";
            throw new BusinessException ( e.getMessage () );
        }
        systemService.addLog ( message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO );
        j.setMsg ( message );
        return j;
    }

    /**
     * @param request
     * @return
     * @author xiul
     * 2016-4-25 下午6:56:03
     * Description 流程 - 巴可商务主管分派任务之前查询任务是否可以分派
     */
    @ResponseBody
    @RequestMapping(params = "checkPlanState")
    public AjaxJson checkPlanState(HttpServletRequest request) {
        AjaxJson j = new AjaxJson ();
        try {
            String planIds = oConvertUtils.getString ( request.getParameter ( "planIds" ) );
            if (StringUtil.isNotEmpty ( planIds )) {
                String[] planIdsArr = planIds.split ( "," );
                for (String id : planIdsArr) {
                    ZyInspectionPlanEntity zyIP = systemService.get ( ZyInspectionPlanEntity.class, id );
                    //如果巡检计划 状态 既不是 待处理 也不是 第三方拒绝的不能操作
//                    if (!zyIP.getState ().equals ( StaticValue.DIC_PLAN_STATE_TODO )
//                            && !zyIP.getState ().equals ( StaticValue.DIC_PLAN_STATE_THIRDPARTY_REFUSED )) {
                    if (!zyIP.getState ().equals ( StaticValue.DIC_PLAN_STATE_TODO )) {
                        j.setSuccess ( false );
                        j.setMsg ( "存在不能分派的巡检计划" );
                        return j;
                    }
                }
            }
        } catch (Exception e) {
            j.setSuccess ( false );
            e.printStackTrace ();
        }
        return j;
    }

    /**
     * @param request
     * @param planIds 巡检计划ids
     * @return
     * @author xiul
     * 2016-4-5 下午5:04:20
     * Description 流程 - 巴可服务商主管批量分派巡检计划 页面跳转
     */
    @RequestMapping(params = "goBatchSendPlan")
    public ModelAndView goBatchSendPlan(HttpServletRequest request, String planId, String ipCount) {
//		if(StringUtil.isNotEmpty(planIds)){
//			request.setAttribute("planIds", planIds);
//			request.setAttribute("ipCount", ipCount);
//		}
        if (StringUtil.isNotEmpty ( planId )) {
            ZyInspectionPlanEntity zyIp = systemService.get ( ZyInspectionPlanEntity.class, planId );
            request.setAttribute ( "zyIp", zyIp );
        }
        /**
         * update by xiul 2016-08-26 批量分派 传参过长
         */
        if (StringUtil.isNotEmpty ( ipCount )) {
            request.setAttribute ( "ipCount", ipCount );
        }
        return new ModelAndView ( "com/zybk/zy_inspection_plan/zyBatchSendPlan" );
    }

    /**
     * @author xiul
     * 2016-8-26 下午1:48:28
     * Description 流程 - 启动流程 巴可服务商主管批量分派巡检计划
     */
    @ResponseBody
    @RequestMapping(params = "doBatchSendPlan")
    public AjaxJson doBatchSendPlan(HttpServletRequest request) {
        AjaxJson j = new AjaxJson ();
        try {
            j = zyInspectionPlanService.doBatchSendPlan ( request );
        } catch (Exception e) {
            j.setSuccess ( false );
            e.printStackTrace ();
        }
        return j;
    }

    /**
     * @author xiul
     * 2016-4-7 下午4:02:18
     * Description 流程 - 第三方负责人分派工程师 列表页
     */
    @RequestMapping(params = "assignEngineer")
    public ModelAndView thirdPartyAssignEngineerList(HttpServletRequest request) {
        String homePageType = oConvertUtils.getString ( request.getParameter ( "homePageType" ) );
        request.setAttribute ( "homePageType", homePageType );
        return new ModelAndView ( "com/zybk/zy_inspection_plan/zyThirdPartyAssignEngineer" );
    }

    /**
     * @author xiul
     * 2016-4-7 下午5:33:58
     * Description 流程 - 第三方负责人分派工程师 列表
     */
    @RequestMapping(params = "datagridOfAssignEnginner")
    @ResponseBody
    public void datagridOfAssignEnginner(ZyInspectionPlanEntity zyInspectionPlan, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
        CriteriaQuery cq = new CriteriaQuery ( ZyInspectionPlanEntity.class, dataGrid );
        //查询条件组装器
        org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql ( cq, zyInspectionPlan, request.getParameterMap () );
        try {
            TSUser user = ResourceUtil.getSessionUserName ();
//            List<String> idsList = zyWorkFlowService.queryUserProcess ( user.getUserName (), StaticValue.P_PROCESS_INSPECTION, true, null );
//            if (idsList.size () == 0) {
//                idsList.add ( "" );
//            }
//            cq.add ( Restrictions.in ( "id", idsList ) );
//
            List<ZyContactsEntity> zyContactsList = systemService.findByProperty ( ZyContactsEntity.class,"tsBaseUser.id",user.getId () );
            if(zyContactsList.size ()>0){
                List list = new ArrayList (  );
                for (ZyContactsEntity zyContacts : zyContactsList) {
                    list.add ( zyContacts.getId () );
                }
                cq.add (Restrictions.in("contacter.id",list));
            }
            cq.notEq ( "state", StaticValue.DIC_PLAN_STATE_TODO ); //第三方商务待处理状态不可见
            
            // Add start 只显示当年和去年未完成的巡检计划 —Amy
            Calendar cal = Calendar.getInstance ();
            int currYear = cal.get ( Calendar.YEAR );
            cq.or(Restrictions.ge ( "ipPlanDate", DateUtils.str2Date ( currYear + "-01-01", DateUtils.date_sdf ) ), 
            		Restrictions.and(Restrictions.ne("state",StaticValue.DIC_PLAN_STATE_INSPECTION_COMPLETE), Restrictions.ne("state",StaticValue.DIC_PLAN_STATE_INSPECTION_CANCEL)));
            // Add end 只显示当年和去年未完成的巡检计划 —Amy

            Map<String, String[]> paramMap = request.getParameterMap ();//因为生成巡检计划那里设置的ipPlanDate 的日 全 部为 01 所以当只查询 一个月份的时候 起止时间都是 01 即可
            for (String key : paramMap.keySet ()) {
                if (key.equals ( "ipPlanDate_begin" ) && !paramMap.get ( key )[0].equals ( "" )) {
                    cq.add ( Restrictions.ge ( "ipPlanDate", DateUtils.str2Date ( paramMap.get ( key )[0] + "-01", DateUtils.date_sdf ) ) );
                }
                if (key.equals ( "ipPlanDate_end" ) && !paramMap.get ( key )[0].equals ( "" )) {
                    cq.add ( Restrictions.le ( "ipPlanDate", DateUtils.str2Date ( paramMap.get ( key )[0] + "-01", DateUtils.date_sdf ) ) );
                }
            }
            cq.add ();
            this.zyInspectionPlanService.getDataGridReturn ( cq, true );
            Map<String, ZyContactsEntity> ipCtsMap = zyInspectionPlanService.queryCinemaIpContactsMap ();
            for (ZyInspectionPlanEntity zyIp : (List<ZyInspectionPlanEntity>) dataGrid.getResults ()) {
                if (zyIp != null) {
                    //设置省市 同时 显示
                    ZyEquipmentSpareEntity zyEs = zyIp.getEquipmentSpare ();
                    String tsTerritoryVal = "";
                    if (zyEs.getTsTerritory () != null && null != zyEs.getTsTerritory ().getTSTerritory ()) {
                        tsTerritoryVal = zyEs.getTsTerritory ().getTSTerritory ().getTerritoryName () + "," + zyEs.getTsTerritory ().getTerritoryName ();
                    } else if (zyEs.getTsTerritory () != null) {
                        tsTerritoryVal = zyEs.getTsTerritory ().getTerritoryName ();
                    }
                    zyIp.setTsTerritoryVal ( tsTerritoryVal );
					/*//设置计划服务时间 开始 结束同时显示
					if(zyIp.getOrderBeginTime() != null && zyIp.getOrderEndTime() != null){
						zyIp.setOrderBeginToEndVal(DataUtils.date2Str(zyIp.getOrderBeginTime(), new SimpleDateFormat("yyyy-MM-dd")) + " / " +
								DataUtils.date2Str(zyIp.getOrderEndTime(), new SimpleDateFormat("yyyy-MM-dd")) );
					}*/
                    //判断当前巡检计划是否可以操作
                    if (!zyInspectionPlanService.judgeForBatchOperateMission ( zyIp, null, user.getId () )) {
                        zyIp.setOperationAble ( "0" );
                    } else if (zyIp.getIsTrun ().equals ( "" ) || null == zyIp.getIsTrun ()) {
                        zyIp.setOperationAble ( "1" );
                    }

                    // “第三方已分配”、“区域工程师已分配”、“区域工程师拒绝”、“工程师接受”、“工程师拒绝” 可有转派的机会
                    if (null != zyIp.getIsTrun () && zyIp.getIsTrun ().equals ( "1" )) {
                        if (zyIp.getState ().equals ( StaticValue.DIC_PLAN_STATE_THIRDPARTY_ASSIGNED ) ||
                                zyIp.getState ().equals ( StaticValue.DIC_PLAN_STATE_AREA_ENGINEER_ASSIGNED ) ||
                                zyIp.getState ().equals ( StaticValue.DIC_PLAN_STATE_AREA_ENGINEER_REFUSED ) ||
                                zyIp.getState ().equals ( StaticValue.DIC_PLAN_STATE_ENGINEER_ASSIGNED ) ||
                                zyIp.getState ().equals ( StaticValue.DIC_PLAN_STATE_ENGINEER_REFUSED )) {
                            zyIp.setTurnToSend ( "1" );
                        }
                    }
                    String cinemaId = zyEs.getZyCinema () != null ? zyEs.getZyCinema ().getId () : "";
//					ZyContactsEntity zyContact = zyInspectionPlanService.queryCinemaInspectionContact(cinemaId);
                    zyIp.setZyCmIpCt ( ipCtsMap.get ( cinemaId ) );
                }
            }
        } catch (Exception e) {
            throw new BusinessException ( e.getMessage () );
        }
        TagUtil.datagrid ( response, dataGrid );
    }

    /**
     * @author xiul
     * 2016-4-25 下午2:24:04
     * Description 流程 - 第三方负责人的用户 - 查看 - 巡检计划详情页
     */
    @RequestMapping(params = "detailsOfTpPlan")
    public ModelAndView detailsOfTpPlan(HttpServletRequest request) {
        TSUser user = ResourceUtil.getSessionUserName ();
        String id = oConvertUtils.getString ( request.getParameter ( "id" ) );
        ZyInspectionPlanEntity zyIP = zyInspectionPlanService.get ( ZyInspectionPlanEntity.class, id );
        TSType state = zyCommonService.queryTsType ( StaticValue.DIC_PLAN_STATE, zyIP.getState () );
        TSType lightPath = zyCommonService.queryTsType ( StaticValue.DIC_LIGHT_PATH, zyIP.getLightPath () );
        zyIP.setStateVal ( state.getTypename () );
        zyIP.setLightPathVal ( lightPath != null ? lightPath.getTypename () : "" );
        request.setAttribute ( "zyIP", zyIP );
        //设备单拿出来
        request.setAttribute ( "zyES", zyIP.getEquipmentSpare () );
        //巡检单位
        List<TSDepart> tsDeparts = zyCommonService.queryOrgByOrgTypeAndBusScope ( StaticValue.DIC_ORG_TYPE_THIRD_PARTY, StaticValue.DIC_BUS_SCOPE_INSPECTION );
        request.setAttribute ( "tsDeparts", tsDeparts );
        //保存按钮
        request.setAttribute ( "btnSavePlanFlag", zyInspectionPlanService.judgeForBatchOperateMission ( zyIP, null, user.getId () ) );//这里修改为 直接存入 布尔值 在前台判断
        //影院技术主管
        List<ZyContactsEntity> cinemaContacts =
                systemService.findHql ( "from ZyContactsEntity where belongCinema.id =? and position =? and state = ? and isDelete = ?",
                        null != zyIP.getEquipmentSpare ().getZyCinema () ? zyIP.getEquipmentSpare ().getZyCinema ().getId () : "", StaticValue.DIC_CONTACT_POSITION_C_TECHNICAL_DIRECTOR, StaticValue.DIC_ENGINEER_STATE_ONJOB, "0" );
        request.setAttribute ( "cmContactTechnicalDirector", cinemaContacts != null && cinemaContacts.size () > 0 ? cinemaContacts.get ( 0 ) : "" );
        //影院巡检联系人单查
        String cinemaId = zyIP.getEquipmentSpare ().getZyCinema () != null ? zyIP.getEquipmentSpare ().getZyCinema ().getId () : "";
        ZyContactsEntity zyCmIpContact = zyInspectionPlanService.queryCinemaInspectionContact ( cinemaId );
        request.setAttribute ( "zyCmIpContact", zyCmIpContact );
        //是否显示 按钮查看巡检报告标示
        request.setAttribute ( "viewOrUpdateReportFlag", zyInspectionPlanService.judgeViewOrUpdateReport ( zyIP.getId () ) );
        return new ModelAndView ( "com/zybk/zy_inspection_plan/zyIpDetialsOfTpAssignEngineer" );
    }

    /**
     * @param planIds 巡检计划 主键ID
     * @author xiul
     * 2016-4-7 下午5:36:40
     * Description 流程 - 第三方具体指派工程师页面
     */
    @RequestMapping(params = "goBatchAssignEngineer")
    public ModelAndView goBatchAssignEngineer(HttpServletRequest request, String planIds) {
        request.setAttribute ( "planIds", planIds );
        String[] ids = planIds.split ( "," );
        if (ids != null && ids.length > 0) {
            ZyInspectionPlanEntity plan = zyInspectionPlanService.get ( ZyInspectionPlanEntity.class, ids[0].toString () );
            request.setAttribute ( "company", plan.getCompany () );
            request.setAttribute ( "ipCount", ids.length );
        }
        return new ModelAndView ( "com/zybk/zy_inspection_plan/zyBatchAssignEngineer" );
    }

    /**
     * @param planIds 巡检计划 主键ID
     * @author xiul
     * 2016-4-7 下午5:36:40
     * Description 流程 - 第三方具体转派工程师页面
     */
    @RequestMapping(params = "goBatchAssignEngineers")
    public ModelAndView goBatchAssignEngineers(HttpServletRequest request, String planIds) {
        request.setAttribute ( "planIds", planIds );
        String[] ids = planIds.split ( "," );
        if (ids != null && ids.length > 0) {
            ZyInspectionPlanEntity plan = zyInspectionPlanService.get ( ZyInspectionPlanEntity.class, ids[0].toString () );
            request.setAttribute ( "company", plan.getCompany () );
            request.setAttribute ( "ipCount", ids.length );
        }
        return new ModelAndView ( "com/zybk/zy_inspection_plan/zyBatchAssignEngineers" );
    }


    /**
     * @param company rolecode 权限code
     * @author xiul
     * 2016-4-11 下午4:35:22
     * Description  流程 - 第三方负责人分派工程师 选择巡检工程师弹出页
     */
    @RequestMapping(params = "zyChooseEngineerList")
    public ModelAndView zyChooseEngineerList(HttpServletRequest request, String company, String planIds) {
        request.setAttribute ( "params", "&orgCode=" + company + "&planIds=" + planIds );
        return new ModelAndView ( "com/zybk/zy_inspection_plan/zyChooseEngineerList" );
    }

    /**
     * @param planIds 巡检计划ID
     * @param orgCode 页面选择的巡检单位值
     * @author xiul
     * 2016-3-30 下午4:58:05
     * Description 流程 - 第三方负责人分派工程师 选择巡检工程师弹出页 datagrid
     */
    @RequestMapping(params = "chooseEngineerDatagrid")
    public void chooseEngineerDatagrid(ZyContactsEntity zyContacter, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid, String orgCode, String planIds) {
        try {
            zyInspectionPlanService.queryDatagridResultForChooseEngineers ( request, dataGrid, orgCode, planIds );
        } catch (Exception e) {
            throw new BusinessException ( e.getMessage () );
        }
        TagUtil.datagrid ( response, dataGrid );
    }

    /**
     * @author xiul
     * 2016-4-11 下午5:11:08
     * Description 流程 - 第三方负责人批量拒绝任务 和 分派任务之前判断是否存在不能拒绝或者分派的任务
     */
    @ResponseBody
    @RequestMapping(params = "doJudgeForBatchRefuseMission")
    public AjaxJson doJudgeForBatchRefuseMission(HttpServletRequest request) {
        AjaxJson j = new AjaxJson ();
        try {
            TSUser user = ResourceUtil.getSessionUserName ();
            String ids = oConvertUtils.getString ( request.getParameter ( "planIds" ) );
            //判断是拒绝操作，还是分派操作
            String type = oConvertUtils.getString ( request.getParameter ( "type" ) );

            String[] idsArr = ids.split ( "," );
            if (idsArr != null && idsArr.length > 0) {
                for (String id : idsArr) {
                    ZyInspectionPlanEntity zyIp = systemService.getEntity ( ZyInspectionPlanEntity.class, id );
                    //拒绝操作
                    if(type.equals ( "1" )){
                        if (!zyInspectionPlanService.judgeForBatchOperateMissionPlan ( zyIp, j, user.getId () )) {
                            return j;
                        }
                    }else{
                        if (!zyInspectionPlanService.judgeForBatchOperateMission ( zyIp, j, user.getId () )) {
                            return j;
                        }
                    }
                }
            }
        } catch (Exception e) {
            j.setMsg ( e.getMessage () );
            j.setSuccess ( false );
            e.printStackTrace ();
        }
        return j;
    }

    /**
     * 流程 - 第三方负责人  《 转派 》  任务之前判断是否存在不能拒绝或者分派的任务
     *
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(params = "doJudgeForBatchRefuseMissions")
    public AjaxJson doJudgeForBatchRefuseMissions(HttpServletRequest request) {
        AjaxJson j = new AjaxJson ();
        try {
            TSUser user = ResourceUtil.getSessionUserName ();
            String ids = oConvertUtils.getString ( request.getParameter ( "planIds" ) );
            String[] idsArr = ids.split ( "," );
            if (idsArr != null && idsArr.length > 0) {
                for (String id : idsArr) {
                    ZyInspectionPlanEntity zyIp = systemService.getEntity ( ZyInspectionPlanEntity.class, id );
                    if (!zyInspectionPlanService.judgeForBatchOperateMissions ( zyIp, j, user.getId () )) {
                        return j;
                    }
                }
            }
        } catch (Exception e) {
            j.setMsg ( e.getMessage () );
            j.setSuccess ( false );
            e.printStackTrace ();
        }
        return j;
    }

    /**
     * @author xiul
     * 2016-4-11 下午5:11:08
     * Description 流程 - 第三方负责人批量分配工程师
     */
    @ResponseBody
    @RequestMapping(params = "doBatchAssignEngineer")
    public AjaxJson doBatchAssignEngineer(HttpServletRequest request, ZyInspectionPlanEntity zyinpInspectionPlanEntity) {
        AjaxJson j = new AjaxJson ();
        String planIds = oConvertUtils.getString ( request.getParameter ( "planIds" ) );
        try {
            zyInspectionPlanService.doBatchAssignEngineer ( planIds, zyinpInspectionPlanEntity );
        } catch (Exception e) {
            e.printStackTrace ();
        }
        return j;
    }

    /**
     * @author xiul
     * 2016-4-11 下午5:11:08
     * Description 流程 - 第三方负责人批量转派工程师
     */
    @ResponseBody
    @RequestMapping(params = "doBatchAssignEngineers")
    public AjaxJson doBatchAssignEngineers(HttpServletRequest request, ZyInspectionPlanEntity zyinpInspectionPlanEntity) {
        AjaxJson j = new AjaxJson ();
        String planIds = oConvertUtils.getString ( request.getParameter ( "planIds" ) );
        String engineerName = oConvertUtils.getString ( request.getParameter ( "engineerName" ) );
        try {
            AjaxJson a = zyInspectionPlanService.doBatchAssignEngineers ( planIds,engineerName,zyinpInspectionPlanEntity );
            j.setSuccess ( a.isSuccess () );
            j.setMsg ( a.getMsg () );

        } catch (Exception e) {
            e.printStackTrace ();
        }
        return j;
    }

    /**
     * @author xiul
     * 2016-6-13 上午11:58:59
     * Description 第三方负责人批量拒绝任务
     */
    @RequestMapping(params = "goBatchRefuseMission")
    public ModelAndView goBatchRefuseMission(HttpServletRequest req) {
        req.setAttribute ( "planIds", req.getParameter ( "planIds" ) );
        return new ModelAndView ( "com/zybk/zy_inspection_plan/zyTpBatchRefuseMission" );
    }


    /**
     * 拒绝操作页面，上传附件功能
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(params = "remarkFileUploadView")
    public AjaxJson remarkFileUploadView(HttpServletRequest request) {
        AjaxJson j = new AjaxJson ();
        Map<String, Object> attributes = new HashMap<String, Object> ();
        //获取拒绝操作的类型
        FileBean fileBean = UploadFileUtil.UploadFile ( request );
        ZyFileLogEntity zyfileLog = new ZyFileLogEntity ();
        zyfileLog.setFilePath ( fileBean.getSavePath () );
        zyfileLog.setOldFileName ( fileBean.getFileRealName () );
        zyfileLog.setNewFileName ( fileBean.getFileName () );
        systemService.save ( zyfileLog );
        attributes.put("fileKey", zyfileLog.getId());
        attributes.put ( "name", fileBean.getFileRealName () );
        j.setAttributes ( attributes );
        return j;

    }


    /**
     * @author xiul
     * 2016-4-11 下午5:11:08
     * Description 流程 - 第三方负责人批量拒绝任务
     */
    @ResponseBody
    @RequestMapping(params = "doBatchRefuseMission")
    public AjaxJson doBatchRefuseMission(HttpServletRequest request) {
        AjaxJson j = new AjaxJson ();
        String planIds = oConvertUtils.getString ( request.getParameter ( "planIds" ) );
        String remark = oConvertUtils.getString ( request.getParameter ( "remark" ) );
        String fileId = oConvertUtils.getString ( request.getParameter ( "fileId" ) );
        try {
            message = zyInspectionPlanService.doBatchRefuseMission ( planIds, remark,fileId);
            j.setMsg ( message );
            j.setSuccess ( true );
        } catch (Exception e) {
            j.setMsg ( e.getMessage () );
            j.setSuccess ( false );
            e.printStackTrace ();
        }
        return j;
    }

    /**
     * @author xiul
     * 2016-4-7 下午4:02:18
     * Description 流程 - 区域工程师分派工程师 列表页
     */
    @RequestMapping(params = "areaEngineerAssignEngineer")
    public ModelAndView areaEngineerAssignEngineerList(HttpServletRequest request) {
        String optRule = StaticValue.DIC_PLAN_STATE_THIRDPARTY_ASSIGNED + ",";
        optRule += StaticValue.DIC_PLAN_STATE_ENGINEER_REFUSED;
        request.setAttribute ( "optRule", optRule );
        return new ModelAndView ( "com/zybk/zy_inspection_plan/zyAreaEngineerAssignEngineerList" );
    }

    /**
     * @author xiul
     * 2016-4-7 下午5:33:58
     * Description 流程 - 区域工程师分派工程师 列表
     */
    @RequestMapping(params = "datagridOfAreaEngineerAssignEnginner")
    @ResponseBody
    public void datagridOfAreaEngineerAssignEnginner(ZyInspectionPlanEntity zyInspectionPlan, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
        CriteriaQuery cq = new CriteriaQuery ( ZyInspectionPlanEntity.class, dataGrid );
        //查询条件组装器
        org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql ( cq, zyInspectionPlan, request.getParameterMap () );
        try {
            TSUser user = ResourceUtil.getSessionUserName ();
//            List<String> idsList = zyWorkFlowService.queryUserProcess ( user.getUserName (), StaticValue.P_PROCESS_INSPECTION, true, null );
//            if (idsList.size () == 0) {
//                idsList.add ( "" );
//            }
//            cq.add ( Restrictions.in ( "id", idsList ) );
            List<ZyEngineerEntity> zyEngineerEntities = systemService.findByProperty ( ZyEngineerEntity.class,"tsBaseUser.id",user.getId () );
            if(zyEngineerEntities.size ()>0){
                List list = new ArrayList (  );
                for (ZyEngineerEntity zyEngineerEntity : zyEngineerEntities) {
                    list.add ( zyEngineerEntity.getId () );
                }
                cq.add (Restrictions.in("areaEngineer.id",list));
            }
            // Add start 只显示当年和去年未完成的巡检计划 —Amy
            Calendar cal = Calendar.getInstance ();
            int currYear = cal.get ( Calendar.YEAR );
            cq.or(Restrictions.ge ( "ipPlanDate", DateUtils.str2Date ( currYear + "-01-01", DateUtils.date_sdf ) ), 
            		Restrictions.and(Restrictions.ne("state",StaticValue.DIC_PLAN_STATE_INSPECTION_COMPLETE), Restrictions.ne("state",StaticValue.DIC_PLAN_STATE_INSPECTION_CANCEL)));
            // Add end 只显示当年和去年未完成的巡检计划 —Amy
            cq.add ();
            this.zyInspectionPlanService.getDataGridReturn ( cq, true );
            Map<String, ZyContactsEntity> ipCtsMap = zyInspectionPlanService.queryCinemaIpContactsMap ();
            for (ZyInspectionPlanEntity zyIp : (List<ZyInspectionPlanEntity>) dataGrid.getResults ()) {
                if (zyIp != null) {
                    //设置省市 同时 显示
                    ZyEquipmentSpareEntity zyEs = zyIp.getEquipmentSpare ();
                    String tsTerritoryVal = "";
                    if (zyEs.getTsTerritory () != null && null != zyEs.getTsTerritory ().getTSTerritory ()) {
                        tsTerritoryVal = zyEs.getTsTerritory ().getTSTerritory ().getTerritoryName () + "," + zyEs.getTsTerritory ().getTerritoryName ();
                    } else if (zyEs.getTsTerritory () != null) {
                        tsTerritoryVal = zyEs.getTsTerritory ().getTerritoryName ();
                    }
                    zyIp.setTsTerritoryVal ( tsTerritoryVal );
					/*//设置计划服务时间 开始 结束同时显示
					if(zyIp.getOrderBeginTime() != null && zyIp.getOrderEndTime() != null){
						zyIp.setOrderBeginToEndVal(DataUtils.date2Str(zyIp.getOrderBeginTime(), new SimpleDateFormat("yyyy-MM-dd")) + " / " +
								DataUtils.date2Str(zyIp.getOrderEndTime(), new SimpleDateFormat("yyyy-MM-dd")) );
					}*/
                    String cinemaId = zyEs.getZyCinema () != null ? zyEs.getZyCinema ().getId () : "";
//					ZyContactsEntity zyContact = zyInspectionPlanService.queryCinemaInspectionContact(cinemaId);
                    zyIp.setZyCmIpCt ( ipCtsMap.get ( cinemaId ) );
                }
            }
        } catch (Exception e) {
            throw new BusinessException ( e.getMessage () );
        }
        TagUtil.datagrid ( response, dataGrid );
    }

    /**
     * @return
     * @author xiul
     * 2016-4-25 下午2:24:04
     * Description 区域工程师 用户 - 查看 - 巡检任务详情页
     */
    @RequestMapping(params = "detailsOfAreaEngineerPlan")
    public ModelAndView detailsOfAreaEngineerPlan(HttpServletRequest request) {
        TSUser user = ResourceUtil.getSessionUserName ();
        String id = oConvertUtils.getString ( request.getParameter ( "id" ) );
        ZyInspectionPlanEntity zyIP = zyInspectionPlanService.get ( ZyInspectionPlanEntity.class, id );
        TSType state = zyCommonService.queryTsType ( StaticValue.DIC_PLAN_STATE, zyIP.getState () );
        TSType lightPath = zyCommonService.queryTsType ( StaticValue.DIC_LIGHT_PATH, zyIP.getLightPath () );
        zyIP.setStateVal ( state.getTypename () );
        zyIP.setLightPathVal ( lightPath != null ? lightPath.getTypename () : "" );
        request.setAttribute ( "zyIP", zyIP );
        //设备单拿出来
        request.setAttribute ( "zyES", zyIP.getEquipmentSpare () );
        //巡检单位
        List<TSDepart> tsDeparts = zyCommonService.queryOrgByOrgTypeAndBusScope ( StaticValue.DIC_ORG_TYPE_THIRD_PARTY, StaticValue.DIC_BUS_SCOPE_INSPECTION );
        request.setAttribute ( "tsDeparts", tsDeparts );
        //按钮 保存
        request.setAttribute ( "btnSavePlanFlag", zyInspectionPlanService.judgeForAreaEngineerAssignEngineer ( zyIP.getId (), null, user.getId () ) );//这里修改为 直接存入 布尔值 在前台判断
        List<ZyContactsEntity> cinemaContacts =
                systemService.findHql ( "from ZyContactsEntity where belongCinema.id =? and position =?", null != zyIP.getEquipmentSpare ().getZyCinema () ? zyIP.getEquipmentSpare ().getZyCinema ().getId () : "", StaticValue.DIC_CONTACT_POSITION_C_TECHNICAL_DIRECTOR );
        request.setAttribute ( "cinemaContact", cinemaContacts != null && cinemaContacts.size () > 0 ? cinemaContacts.get ( 0 ) : "" );
        //影院巡检联系人单查
        String cinemaId = zyIP.getEquipmentSpare ().getZyCinema () != null ? zyIP.getEquipmentSpare ().getZyCinema ().getId () : "";
        ZyContactsEntity zyCmIpContact = zyInspectionPlanService.queryCinemaInspectionContact ( cinemaId );
        request.setAttribute ( "zyCmIpContact", zyCmIpContact );
        //是否显示 按钮查看巡检报告 标示
        request.setAttribute ( "viewOrUpdateReportFlag", zyInspectionPlanService.judgeViewOrUpdateReport ( zyIP.getId () ) );
        return new ModelAndView ( "com/zybk/zy_inspection_plan/zyIpDetialsOfAreaEngineer" );
    }

    /**
     * @param request
     * @param planIds
     * @return
     * @author xiul
     * 2016-4-19 上午10:06:00
     * Description 流程 - 区域工程师指派工程师页面
     */
    @RequestMapping(params = "goBatchAreaAssignEngineer")
    public ModelAndView goBatchAreaAssignEngineer(HttpServletRequest request, String planIds) {
        request.setAttribute ( "planIds", planIds );
        String[] ids = planIds.split ( "," );
        if (ids != null && ids.length > 0) {
            ZyInspectionPlanEntity plan = zyInspectionPlanService.get ( ZyInspectionPlanEntity.class, ids[0].toString () );
            request.setAttribute ( "zyInspectionPlan", plan );
            request.setAttribute ( "company", plan.getCompany () );
            request.setAttribute ( "ipCount", ids.length );
        }
        return new ModelAndView ( "com/zybk/zy_inspection_plan/zyBatchAreaAssignEngineer" );
    }

    /**
     * @param request
     * @param company rolecode 权限code
     * @return
     * @author xiul
     * 2016-4-11 下午4:35:22
     * Description  流程 - 区域工程师分派工程师 选择巡检工程师弹出页 datagrid
     */
    @RequestMapping(params = "zyAreaChooseEngineerList")
    public ModelAndView zyAreaChooseEngineerList(HttpServletRequest request, String company, String planIds) {
        request.setAttribute ( "params", "&orgCode=" + company + "&planIds=" + planIds );
        return new ModelAndView ( "com/zybk/zy_inspection_plan/zyAreaChooseEngineerList" );
    }

    /**
     * @param planIds 巡检计划ID
     * @param orgCode 页面选择的巡检单位值
     * @author xiul
     * 2016-3-30 下午4:58:05
     * Description 流程 -  区域工程师 指派具体工程师页面 datagrid
     */
    @RequestMapping(params = "areaChooseEngineerDatagrid")
    public void areaChooseEngineerDatagrid(ZyContactsEntity zyContacter, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid, String orgCode, String planIds) {
        try {
            zyInspectionPlanService.queryDatagridResultForAreaChooseEngineers ( request, dataGrid, orgCode, planIds );
        } catch (Exception e) {
            throw new BusinessException ( e.getMessage () );
        }
        TagUtil.datagrid ( response, dataGrid );
    }

    /**
     * @param request
     * @author xiul
     * 2016-4-12 上午10:53:31
     * Description  流程 - 在区域工程师 拒单 或 指派工程师之前查询 是否包含不能操作的任务
     */
    @ResponseBody
    @RequestMapping(params = "doJudgeForAreaEngineerAssignEngineer")
    public AjaxJson doJudgeForAreaEngineerAssignEngineer(HttpServletRequest request) {
        AjaxJson j = new AjaxJson ();
        try {
            TSUser user = ResourceUtil.getSessionUserName ();
            String ids = oConvertUtils.getString ( request.getParameter ( "planIds" ) );
            String type = oConvertUtils.getString ( request.getParameter ( "type" ) );
            String[] idsArr = ids.split ( "," );
            if (idsArr != null && idsArr.length > 0) {
                for (String id : idsArr) {
                    /*区域工程师 拒单*/
                    if(type.equals ( "1" )){
                        if (!zyInspectionPlanService.judgeForAreaEngineerAssignEngineerPlan ( id, j, user.getId () )) {
                            return j;
                        }
                    }else{
                        if (!zyInspectionPlanService.judgeForAreaEngineerAssignEngineer ( id, j, user.getId () )) {
                            return j;
                        }
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace ();
        }
        return j;
    }

    /**
     * @param request
     * @param planIds
     * @return
     * @author xiul
     * 2016-4-12 上午11:22:40
     * Description 流程 - 区域工程师指派工程师
     */
    @ResponseBody
    @RequestMapping(params = "doBatchAreaAssignEngineer")
    public AjaxJson doBatchAreaAssignEngineer(HttpServletRequest request) {
        AjaxJson j = new AjaxJson ();
        try {
            String planIds = oConvertUtils.getString ( request.getParameter ( "planIds" ) );
            String engineerId = oConvertUtils.getString ( request.getParameter ( "engineer.id" ) );
            String orderBeginTimeStr = oConvertUtils.getString ( request.getParameter ( "orderBeginTime" ) );
            String orderEndTimeStr = oConvertUtils.getString ( request.getParameter ( "orderEndTime" ) );
            zyInspectionPlanService.doBatchAreaAssignEngineer ( planIds, engineerId, orderBeginTimeStr, orderEndTimeStr );
        } catch (Exception e) {
            j.setSuccess ( false );
            j.setMsg ( "指派失败" );
            e.printStackTrace ();
        }
        return j;
    }

    /**
     * @author xiul
     * 2016-6-13 下午2:25:08
     * Description 区域工程师批量拒绝工程师页面跳转
     */
    @RequestMapping(params = "goBatchAegRefuseMission")
    public ModelAndView goBatchAegRefuseMission(HttpServletRequest req) {
        req.setAttribute ( "planIds", req.getParameter ( "planIds" ) );
        return new ModelAndView ( "com/zybk/zy_inspection_plan/zyAegBatchRefuseMission" );
    }

    /**
     * @param request
     * @return
     * @author xiul
     * 2016-4-11 下午5:11:08
     * Description 流程 - 区域工程师拒单
     */
    @ResponseBody
    @RequestMapping(params = "doBatchRefuseMissionOfAreaEngineer")
    public AjaxJson doBatchRefuseMissionOfAreaEngineer(HttpServletRequest request) {
        AjaxJson j = new AjaxJson ();
        try {
            String planIds = request.getParameter ( "planIds" );
            String remark = request.getParameter ( "remark" );
            String fileId = request.getParameter ( "fileId" );

            message = zyInspectionPlanService.doBatchRefuseMissionOfAreaEngineer ( planIds, remark,fileId );
            j.setMsg ( message );
            j.setSuccess ( true );
        } catch (Exception e) {
            j.setMsg ( e.getMessage () );
            j.setSuccess ( false );
            e.printStackTrace ();
        }
        return j;
    }

    /**
     * @param request
     * @return
     * @author xiul
     * 2016-4-11 下午7:30:51
     * Description 流程 - 工程师 查看任务列表 页面
     */
    @RequestMapping(params = "engineerInspectionPlanList")
    public ModelAndView engineerInspectionPlanList(HttpServletRequest request) {
        request.setAttribute ( "reportRules", StaticValue.DIC_PLAN_STATE_ENGINEER_IN_IMPLEMENT );
        return new ModelAndView ( "com/zybk/zy_inspection_plan/zyEngineerInspectionPlanList" );
    }

    /**
     * @param request
     * @author xiul
     * 2016-4-11 下午8:00:58
     * Description  流程 - 工程师 巡检任务列表
     */
    @RequestMapping(params = "engineerInspectionPlanListDatagrid")
    public void engineerInspectionPlanListDatagrid(ZyInspectionPlanEntity zyInspectionPlan, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
        CriteriaQuery cq = new CriteriaQuery ( ZyInspectionPlanEntity.class, dataGrid );
        org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql ( cq, zyInspectionPlan, request.getParameterMap () );
        try {
            TSBaseUser user = ResourceUtil.getSessionUserName ();
            List<ZyEngineerEntity> zyEngineerEntities = systemService.findByProperty ( ZyEngineerEntity.class,"tsBaseUser.id",user.getId () );
//            List<String> idsList = zyWorkFlowService.queryUserProcess ( user.getUserName (), StaticValue.P_PROCESS_INSPECTION, true, StaticValue.P_PROCESS_INSPECTION_TASKNODE03_2 );
//            if (idsList.size () == 0) {
//                idsList.add ( "" );
//            }
//            cq.add ( Restrictions.in ( "id", idsList ) );
            if(zyEngineerEntities.size ()>0){
                List list = new ArrayList (  );
                for (ZyEngineerEntity zyEngineerEntity : zyEngineerEntities) {
                    list.add ( zyEngineerEntity.getId () );
                }
                cq.add (Restrictions.in("engineer.id",list));
            }
            // Add start 只显示当年和去年未完成的巡检计划 —Amy
            Calendar cal = Calendar.getInstance ();
            int currYear = cal.get ( Calendar.YEAR );
            cq.or(Restrictions.ge ( "ipPlanDate", DateUtils.str2Date ( currYear + "-01-01", DateUtils.date_sdf ) ), 
            		Restrictions.and(Restrictions.ne("state",StaticValue.DIC_PLAN_STATE_INSPECTION_COMPLETE), Restrictions.ne("state",StaticValue.DIC_PLAN_STATE_INSPECTION_CANCEL)));
            // Add end 只显示当年和去年未完成的巡检计划 —Amy
            cq.add ();
            this.zyInspectionPlanService.getDataGridReturn ( cq, true );
            Map<String, ZyContactsEntity> ipCtsMap = zyInspectionPlanService.queryCinemaIpContactsMap ();
            for (ZyInspectionPlanEntity zyIp : (List<ZyInspectionPlanEntity>) dataGrid.getResults ()) {
                if (zyIp != null) {
                    //设置省市 同时 显示
                    ZyEquipmentSpareEntity zyEs = zyIp.getEquipmentSpare ();
                    String tsTerritoryVal = "";
                    if (zyEs.getTsTerritory () != null && null != zyEs.getTsTerritory ().getTSTerritory ()) {
                        tsTerritoryVal = zyEs.getTsTerritory ().getTSTerritory ().getTerritoryName () + "," + zyEs.getTsTerritory ().getTerritoryName ();
                    } else if (zyEs.getTsTerritory () != null) {
                        tsTerritoryVal = zyEs.getTsTerritory ().getTerritoryName ();
                    }
                    zyIp.setTsTerritoryVal ( tsTerritoryVal );
					/*//设置计划服务时间 开始 结束同时显示
					if(zyIp.getOrderBeginTime() != null && zyIp.getOrderEndTime() != null){
						zyIp.setOrderBeginToEndVal(DataUtils.date2Str(zyIp.getOrderBeginTime(), new SimpleDateFormat("yyyy-MM-dd")) + " / " +
								DataUtils.date2Str(zyIp.getOrderEndTime(), new SimpleDateFormat("yyyy-MM-dd")) );
					}*/
                    String cinemaId = zyEs.getZyCinema () != null ? zyEs.getZyCinema ().getId () : "";
//					ZyContactsEntity zyContact = zyInspectionPlanService.queryCinemaInspectionContact(cinemaId);
                    zyIp.setZyCmIpCt ( ipCtsMap.get ( cinemaId ) );
                }
            }
        } catch (Exception e) {
            throw new BusinessException ( e.getMessage () );
        }
        TagUtil.datagrid ( response, dataGrid );
    }

    /**
     * @author xiul
     * 2016-4-25 下午2:24:04
     * Description 流程 - 第三方工程师的用户 - 查看 - 巡检计划详情页
     */
    @RequestMapping(params = "detailsOfEngineerPlan")
    public ModelAndView detailsOfEngineerPlan(HttpServletRequest request) {
        TSUser user = ResourceUtil.getSessionUserName ();
        String id = oConvertUtils.getString ( request.getParameter ( "id" ) );
        ZyInspectionPlanEntity zyIP = zyInspectionPlanService.get ( ZyInspectionPlanEntity.class, id );
        TSType state = zyCommonService.queryTsType ( StaticValue.DIC_PLAN_STATE, zyIP.getState () );
        TSType lightPath = zyCommonService.queryTsType ( StaticValue.DIC_LIGHT_PATH, zyIP.getLightPath () );
        zyIP.setStateVal ( state.getTypename () );
        zyIP.setLightPathVal ( lightPath != null ? lightPath.getTypename () : "" );
        request.setAttribute ( "zyIP", zyIP );
        //设备单拿出来
        request.setAttribute ( "zyES", zyIP.getEquipmentSpare () );
        //巡检单位
        List<TSDepart> tsDeparts = zyCommonService.queryOrgByOrgTypeAndBusScope ( StaticValue.DIC_ORG_TYPE_THIRD_PARTY, StaticValue.DIC_BUS_SCOPE_INSPECTION );
        request.setAttribute ( "tsDeparts", tsDeparts );
        //按钮 保存 巡检任务的 过滤条件
        request.setAttribute ( "btnSavePlanFlag", zyInspectionPlanService.doJudgeForEgUpdateEgOrderTime ( id, null, user.getId () ) );//这里修改为 直接存入 布尔值 在前台判断
        //影院技术主管
        List<ZyContactsEntity> cinemaContacts =
                systemService.findHql ( "from ZyContactsEntity where belongCinema.id =? and position =?", null != zyIP.getEquipmentSpare ().getZyCinema () ? zyIP.getEquipmentSpare ().getZyCinema ().getId () : "", StaticValue.DIC_CONTACT_POSITION_C_TECHNICAL_DIRECTOR );
        request.setAttribute ( "cinemaContact", cinemaContacts != null && cinemaContacts.size () > 0 ? cinemaContacts.get ( 0 ) : "" );
        //影院巡检联系人单查
        String cinemaId = zyIP.getEquipmentSpare ().getZyCinema () != null ? zyIP.getEquipmentSpare ().getZyCinema ().getId () : "";
        ZyContactsEntity zyCmIpContact = zyInspectionPlanService.queryCinemaInspectionContact ( cinemaId );
        request.setAttribute ( "zyCmIpContact", zyCmIpContact );
        //是否显示 按钮查看巡检报告 标示
        request.setAttribute ( "viewOrUpdateReportFlag", zyInspectionPlanService.judgeViewOrUpdateReport ( zyIP.getId () ) );
        return new ModelAndView ( "com/zybk/zy_inspection_plan/zyIpDetialsOfEngineer" );
    }

    /**
     * @author xiul
     * 2016-4-12 上午10:53:31
     * Description  流程 - 工程师修改预约上门时间之前判断是否可以修改
     */
	/*@ResponseBody
	@RequestMapping(params="doJudgeForEgUpdateIp")
	public AjaxJson doJudgeForEgUpdateIp(HttpServletRequest request){
		AjaxJson j = new AjaxJson();
		try {
			TSUser user = ResourceUtil.getSessionUserName();
			String id = oConvertUtils.getString(request.getParameter("id"));
			if(!zyInspectionPlanService.doJudgeForEgUpdateEgOrderTime(id, j,user.getId())){
				return j;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return j;
	}*/

    /**
     * @author xiul
     * 2016-4-12 上午10:53:31
     * Description  流程 - 工程师修改预约上门时间之前判断是否可以修改
     */
    @ResponseBody
    @RequestMapping(params = "doJudgeForEgUpdateEgOrderTime")
    public AjaxJson doJudgeForEgUpdateEgOrderTime(HttpServletRequest request) {
        AjaxJson j = new AjaxJson ();
        try {
            TSUser user = ResourceUtil.getSessionUserName ();
            String id = oConvertUtils.getString ( request.getParameter ( "id" ) );
            if (!zyInspectionPlanService.doJudgeForEgUpdateEgOrderTime ( id, j, user.getId () )) {
                return j;
            }
        } catch (Exception e) {
            e.printStackTrace ();
        }
        return j;
    }

    /**
     * @author xiul
     * 2016-4-26 下午6:32:01
     * Description 工程师在详情页录入信息
     */
    @ResponseBody
    @RequestMapping(params = "doEngineerUpdateIp")
    public AjaxJson doEngineerUpdateIp(HttpServletRequest request) {
        AjaxJson j = new AjaxJson ();
        try {
            String id = oConvertUtils.getString ( request.getParameter ( "id" ) );
            String engineerOrderTime = oConvertUtils.getString ( request.getParameter ( "engineerOrderTime" ) );
            String engineerRemark = oConvertUtils.getString ( request.getParameter ( "engineerRemark" ) );
            zyInspectionPlanService.doEngineerUpdateIp ( id, engineerOrderTime, engineerRemark );
            j.setMsg ( "保存成功" );
        } catch (Exception e) {
            e.printStackTrace ();
            j.setMsg ( "保存失败" );
            j.setSuccess ( false );
        }
        return j;
    }


    /**
     * @author xiul
     * 2016-4-12 上午10:53:31
     * Description  流程 - 在工程选择填写巡检报告之前判断所选任务是否可以
     */
    @ResponseBody
    @RequestMapping(params = "doJudgePlanOfEngineerAddReport")
    public AjaxJson doJudgePlanOfEngineerAddReport(HttpServletRequest request) {
        AjaxJson j = new AjaxJson ();
        try {
            TSUser user = ResourceUtil.getSessionUserName ();
            String id = oConvertUtils.getString ( request.getParameter ( "id" ) );
            if (!zyInspectionPlanService.judgePlanOfEgAddReport ( id, j, user.getId () )) {
                return j;
            }
//			//工程师只能填写 工程师实施中的巡检计划
//			if(!zyIP.getState().equals(StaticValue.DIC_PLAN_STATE_ENGINEER_IN_IMPLEMENT)){
//				j.setSuccess(false);
//				j.setMsg("所选任务不能填写巡检报告，请重新选择");
//			}
        } catch (Exception e) {
            e.printStackTrace ();
        }
        return j;
    }


    /**
     * @author xiul
     * 2016-4-12 上午10:53:31
     * Description  流程 - 在工程选择 拒绝 和 接受 任务之前判断所选任务中是否包含不能拒绝 和接收的任务
     */
    @ResponseBody
    @RequestMapping(params = "doJudgePlanOfEngineerRefusePlan")
    public AjaxJson doJudgePlanOfEngineerRefusePlan(HttpServletRequest request) {
        AjaxJson j = new AjaxJson ();
        try {
            TSUser user = ResourceUtil.getSessionUserName ();
            String ids = oConvertUtils.getString ( request.getParameter ( "planIds" ) );
            String type = oConvertUtils.getString ( request.getParameter ( "type" ) );
            String[] idsArr = ids.split ( "," );
            if (idsArr != null && idsArr.length > 0) {
                for (String id : idsArr) {
                    if (zyInspectionPlanService.judgeIpOfEgRefusePlan ( id, type, j, user.getId () )) {
                        return j;
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace ();
        }
        return j;
    }

    /**
     * @author xiul
     * 2016-4-12 上午10:45:47
     * Description 流程 - 第三方工程师拒绝巡检任务
     */
    @RequestMapping(params = "goBatchEngineerRefusePlan")
    public ModelAndView goBatchEngineerRefusePlan(HttpServletRequest request, String planIds) {
        request.setAttribute ( "planIds", planIds );
        return new ModelAndView ( "com/zybk/zy_inspection_plan/zyBatchEngineerRefusePlan" );
    }

    /**
     * @author xiul
     * 2016-4-12 上午11:20:34
     * Description 流程 - 工程师拒单
     */
    @ResponseBody
    @RequestMapping(params = "doBatchEngineerRefusePlan")
    public AjaxJson doBatchEngineerRefusePlan(HttpServletRequest request) {
        AjaxJson j = new AjaxJson ();
        try {
            String planIds = oConvertUtils.getString ( request.getParameter ( "planIds" ) );
            String remark = oConvertUtils.getString ( request.getParameter ( "remark" ) );
            String fileId = oConvertUtils.getString ( request.getParameter ( "fileId" ) );
            message = zyInspectionPlanService.doBatchRefuseMissionOfEngineer ( planIds, remark,fileId);
            j.setMsg ( message );
        } catch (Exception e) {
            j.setSuccess ( false );
            j.setMsg ( "拒绝失败" );
            e.printStackTrace ();
        }
        return j;
    }

    /**
     * @author xiul
     * 2016-10-27 下午1:50:08
     * Description 工程师接受任务 - 弹出页
     */
    @RequestMapping(params = "goEgAssignMission")
    public ModelAndView goEgAssignMission(HttpServletRequest req) {
        req.setAttribute ( "planIds", req.getParameter ( "planIds" ) );
        return new ModelAndView ( "com/zybk/zy_inspection_plan/zyEgAssignMission" );
    }

    /**
     * @author xiul
     * 2016-4-12 上午11:22:40
     * Description 流程 - 工程师接单
     */
    @ResponseBody
    @RequestMapping(params = "doBatchEngineerAssignPlan")
    public AjaxJson doBatchEngineerAssignPlan(HttpServletRequest request) {
        AjaxJson j = new AjaxJson ();
        try {
            String planIds = oConvertUtils.getString ( request.getParameter ( "planIds" ) );
            zyInspectionPlanService.doBatchEngineerAssignPlan ( planIds );
            String engineerOrderTime = oConvertUtils.getString ( request.getParameter ( "engineerOrderTime" ) );
            for (String id : planIds.split ( "," )) {
                zyInspectionPlanService.doEngineerUpdateIp ( id, engineerOrderTime, "" );
            }
        } catch (Exception e) {
            j.setSuccess ( false );
            j.setMsg ( "接受失败" );
            e.printStackTrace ();
        }
        return j;
    }

    /**
     * @author xiul
     * 2016-5-9 下午6:35:39
     * Description 根据类型跳转不同页面
     */
    @RequestMapping(params = "viewPlanInHomePage")
    public String viewPlanInHomePage(@RequestParam(value = "type") String type) {
        String view = "";
        String param = "&homePageType=" + type;
        /**
         * 下面的重定向的页面。如果页面中存在不合时宜的固定搜索条件或是其它的问题，影响跳转的目的。需要重新写跳转和datagrid查询。
         * 现在重写的有
         * 1.bsd_ipTodo
         * 2.bsd_ipChange
         * 3.th_ipTodo
         * 4.th_ipChange
         * 5.th_ipOverTime
         * 6.tae_ipHadSend
         * 7.te_ipTodo
         * 8.te_ipChange
         * 9.te_ipDidnotComplete
         * 10.te_ipOverTime
         * 11.te_ipTomorrow
         **/
        switch (type) {
            case "bsd_ipTodo"://1
                view = "redirect:/zyInspectionPlanController.do?zyIpListOfHomePageTask" + param;//巴可主管 巡检管理列表
                break;
            case "bsd_ipChange"://2
                view = "redirect:/zyEquipmentChangeController.do?zyEquipmentChangeApprovalOfHomePageTask" + param;//巴可主管 待审批设备变更
                break;
            case "th_ipTodo"://3
                view = "redirect:/zyInspectionPlanController.do?tpAssignEgListOfHomePageTask" + param;//第三方负责人 分配工程师
                break;
            case "th_ipChange"://4
                view = "redirect:/zyEquipmentChangeController.do?zyEsChangeOfHomePageTask" + param;//第三方 设备变更
                break;
            case "th_ipOverTime"://5
                view = "redirect:/zyInspectionPlanController.do?tpAssignEgListOfHomePageTask" + param;//第三方负责人 分配工程师
                break;
            case "tae_ipHadSend"://6
                view = "redirect:/zyInspectionPlanController.do?aegAssignEgListOfHomePageTask" + param;//第三方区域工程师 任务列表
                break;
            case "te_ipTodo"://7
                view = "redirect:/zyInspectionPlanController.do?egIpListOfHomePageTask" + param;//第三方工程师 任务列表
                break;
            case "te_ipChange"://8
                view = "redirect:/zyEquipmentChangeController.do?zyEsChangeOfHomePageTask" + param;//第三方工程师 设备变更列表
                break;
            case "te_ipDidnotComplete"://9
                view = "redirect:/zyInspectionPlanController.do?egIpListOfHomePageTask" + param;//第三方工程师 任务列表
                break;
            case "te_ipOverTime"://10
                view = "redirect:/zyInspectionPlanController.do?egIpListOfHomePageTask" + param;//第三方工程师 任务列表
                break;
            case "te_ipTomorrow"://11
                view = "redirect:/zyInspectionPlanController.do?egIpListOfHomePageTask" + param;//第三方工程师 任务列表
                break;
            case "hd_ipHadNoIeOverTime"://12
                view = "redirect:/cbsEvaluate.do?listOfHomePageTask" + param;//巴可 巡检管理列表
                break;
            default:
                break;
        }
        return view;
    }

    /**
     * 首页代办 - 巴可主管 待分配巡检计划 - 页面跳转
     */
    @RequestMapping(params = "zyIpListOfHomePageTask")
    public ModelAndView ipListOfHomePageTask(HttpServletRequest request) {
        String homePageType = oConvertUtils.getString ( request.getParameter ( "homePageType" ) );
        request.setAttribute ( "homePageType", homePageType );
        String optRule = StaticValue.DIC_PLAN_STATE_TODO ;
//        String optRule = StaticValue.DIC_PLAN_STATE_TODO + ",";
//        optRule += StaticValue.DIC_PLAN_STATE_THIRDPARTY_REFUSED;
        request.setAttribute ( "optRule", optRule );
        return new ModelAndView ( "com/zybk/zy_inspection_plan/zyIpListOfHomePageTask" );
    }

    /**
     * 首页代办 - 巴可主管 待分配巡检计划 - datagrid
     */
    @RequestMapping(params = "datagridOfIpListOfHomePageTask")
    public void datagridOfIpListOfHomePageTask(ZyInspectionPlanEntity zyInspectionPlan, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
        CriteriaQuery cq = new CriteriaQuery ( ZyInspectionPlanEntity.class, dataGrid );
        org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql ( cq, zyInspectionPlan, request.getParameterMap () );
        try {
            //从首页代办跳转过来
            if (StringUtil.isNotEmpty ( request.getParameter ( "homePageType" ) )) {
                String homePageType = request.getParameter ( "homePageType" );
                if (homePageType.equals ( "bsd_ipTodo" )) {
                    //未派单巡检计划数量：巡检计划没有分派给第三方的数量。
                    List<String> states = new ArrayList<String> ();
                    states.add ( StaticValue.DIC_PLAN_STATE_TODO );
//                    states.add ( StaticValue.DIC_PLAN_STATE_THIRDPARTY_REFUSED );
                    cq.add ( Restrictions.in ( "state", states ) );
                } else if (homePageType.equals ( "hd_ipHadNoIeOverTime" )) {
                    //任务提醒： HD咨询线： 巡检满意度回访超时任务提醒：巡检结束时间后超过一周而尚未进行服务评价的巡检计划数量。
                    StringBuffer sql = new StringBuffer ();
                    sql.append ( " SELECT " );
                    sql.append ( " 	ip.id AS ipId " );
                    sql.append ( " FROM " );
                    sql.append ( " 	zy_inspection_plan ip " );
                    sql.append ( " LEFT JOIN cbs_inspection_evaluate ie ON ie.inspection_id = ip.id " );
                    sql.append ( " WHERE  " );
                    sql.append ( " 	ISNULL(ie.id) " );
                    sql.append ( " 	AND TIMESTAMPDIFF(DAY,NOW(),ip.end_time) > ? " );
                    List<Map<String, Object>> mapList = systemService.findForJdbc ( sql.toString (), 7 );
                    if (null != mapList && mapList.size () > 0) {
                        List<String> ipIds = new ArrayList<String> ();
                        for (Map<String, Object> map : mapList) {
                            ipIds.add ( map.get ( "ipId" ).toString () );
                        }
                        if (ipIds.size () > 0) {
                            cq.add ( Restrictions.in ( "id", ipIds ) );
                        }
                    }
                }
            }
            cq.add ();
            this.zyInspectionPlanService.getDataGridReturn ( cq, true );
            for (ZyInspectionPlanEntity zyIp : (List<ZyInspectionPlanEntity>) dataGrid.getResults ()) {
                if (zyIp != null) {
                    //设置省市 同时 显示
                    String tsTerritoryVal = "";
                    if (zyIp.getEquipmentSpare ().getTsTerritory () != null && null != zyIp.getEquipmentSpare ().getTsTerritory ().getTSTerritory ()) {
                        tsTerritoryVal = zyIp.getEquipmentSpare ().getTsTerritory ().getTSTerritory ().getTerritoryName () + "," + zyIp.getEquipmentSpare ().getTsTerritory ().getTerritoryName ();
                    } else if (zyIp.getEquipmentSpare ().getTsTerritory () != null) {
                        tsTerritoryVal = zyIp.getEquipmentSpare ().getTsTerritory ().getTerritoryName ();
                    }
                    zyIp.setTsTerritoryVal ( tsTerritoryVal );
					/*//设置计划服务时间 开始 结束同时显示
					if(zyIp.getOrderBeginTime() != null && zyIp.getOrderEndTime() != null){
						zyIp.setOrderBeginToEndVal(DataUtils.date2Str(zyIp.getOrderBeginTime(), new SimpleDateFormat("yyyy-MM-dd")) + " / " +
								DataUtils.date2Str(zyIp.getOrderEndTime(), new SimpleDateFormat("yyyy-MM-dd")) );
					}*/
                }
            }
        } catch (Exception e) {
            throw new BusinessException ( e.getMessage () );
        }
        TagUtil.datagrid ( response, dataGrid );
    }

    /**
     * 首页代办 - 第三方 未派单巡检计划数量 & 第三方 超时任务提醒 - 页面跳转
     */
    @RequestMapping(params = "tpAssignEgListOfHomePageTask")
    public ModelAndView tpAssignEgListOfHomePageTask(HttpServletRequest request) {
        String homePageType = oConvertUtils.getString ( request.getParameter ( "homePageType" ) );
        request.setAttribute ( "homePageType", homePageType );
        return new ModelAndView ( "com/zybk/zy_inspection_plan/zyTpAssignEgOfHomePageTask" );
    }

    /**
     * 首页代办 - 第三方 未派单巡检计划数量 & 第三方 超时任务提醒 - datagrid
     */
    @RequestMapping(params = "datagridOfAssignEgOfHomePageTask")
    @ResponseBody
    public void datagridOfAssignEgOfHomePageTask(ZyInspectionPlanEntity zyInspectionPlan, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
        CriteriaQuery cq = new CriteriaQuery ( ZyInspectionPlanEntity.class, dataGrid );
        //查询条件组装器
        org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql ( cq, zyInspectionPlan, request.getParameterMap () );
        try {
            TSUser user = ResourceUtil.getSessionUserName ();
            //如果是从首页跳转过来
            if (StringUtil.isNotEmpty ( request.getParameter ( "homePageType" ) )) {
                String homePageType = request.getParameter ( "homePageType" );
                TSDepart rootDepart = zyCommonService.getUserRootTsDepartCode ( user.getCurrentDepart () );//最上级组织（公司）
                String company = rootDepart.getOrgCode ();
                if (homePageType.equals ( "th_ipTodo" )) {
					/*未派单巡检计划数量：本公司接受的巡检计划中没有分配给工程师的数量。*/
                    cq.add ( Restrictions.like ( "company", company + "%" ) );
                    //1：巡检单位中 有区域工程师
                    List<String> statesHadAreaEg = new ArrayList<String> ();
                    statesHadAreaEg.add ( StaticValue.DIC_PLAN_STATE_SEND_TO_THIRDPARTY );
                    statesHadAreaEg.add ( StaticValue.DIC_PLAN_STATE_AREA_ENGINEER_REFUSED );
                    //2：没有区域工程师
                    List<String> statesHadNotAreaEg = new ArrayList<String> ();
                    statesHadNotAreaEg.add ( StaticValue.DIC_PLAN_STATE_SEND_TO_THIRDPARTY );
                    statesHadNotAreaEg.add ( StaticValue.DIC_PLAN_STATE_ENGINEER_REFUSED );

                    cq.or ( Restrictions.and ( Restrictions.eq ( "companyHadAreaEg", "1" ), Restrictions.in ( "state", statesHadAreaEg ) ),
                            Restrictions.and ( Restrictions.eq ( "companyHadAreaEg", "0" ), Restrictions.in ( "state", statesHadNotAreaEg ) ) );
                } else if (homePageType.equals ( "th_ipOverTime" )) {
					/*超时任务提醒：本公司工程师在指定的预约上门时间48小时后还未提交巡检报告的巡检计划的总数量。*/
                    String overTimeStates = "'" + StaticValue.DIC_PLAN_STATE_INSPECTION_COMPLETE + "',";
                    overTimeStates += "'" + StaticValue.DIC_PLAN_STATE_INSPECTION_CANCEL + "'";
                    List<Map<String, Object>> idsMap =
                            systemService.findForJdbc ( "SELECT id FROM zy_inspection_plan WHERE company LIKE ? AND state not in (" + overTimeStates + ") AND TIMESTAMPDIFF(HOUR ,engineer_order_time,NOW()) > 48 ", company + "%" );
                    List<String> ids = new ArrayList<String> ();
                    for (Map<String, Object> map : idsMap) {
                        ids.add ( map.get ( "id" ).toString () );
                    }
                    cq.add ( Restrictions.in ( "id", ids ) );
                }
            }
            cq.add ();
            this.zyInspectionPlanService.getDataGridReturn ( cq, true );
            Map<String, ZyContactsEntity> ipCtsMap = zyInspectionPlanService.queryCinemaIpContactsMap ();
            for (ZyInspectionPlanEntity zyIp : (List<ZyInspectionPlanEntity>) dataGrid.getResults ()) {
                if (zyIp != null) {
                    //设置省市 同时 显示
                    ZyEquipmentSpareEntity zyEs = zyIp.getEquipmentSpare ();
                    String tsTerritoryVal = "";
                    if (zyEs.getTsTerritory () != null && null != zyEs.getTsTerritory ().getTSTerritory ()) {
                        tsTerritoryVal = zyEs.getTsTerritory ().getTSTerritory ().getTerritoryName () + "," + zyEs.getTsTerritory ().getTerritoryName ();
                    } else if (zyEs.getTsTerritory () != null) {
                        tsTerritoryVal = zyEs.getTsTerritory ().getTerritoryName ();
                    }
                    zyIp.setTsTerritoryVal ( tsTerritoryVal );
					/*//设置计划服务时间 开始 结束同时显示
					if(zyIp.getOrderBeginTime() != null && zyIp.getOrderEndTime() != null){
						zyIp.setOrderBeginToEndVal(DataUtils.date2Str(zyIp.getOrderBeginTime(), new SimpleDateFormat("yyyy-MM-dd")) + " / " +
								DataUtils.date2Str(zyIp.getOrderEndTime(), new SimpleDateFormat("yyyy-MM-dd")) );
					}*/
                    //判断当前巡检计划是否可以操作
                    if (!zyInspectionPlanService.judgeForBatchOperateMission ( zyIp, null, user.getId () )) {
                        zyIp.setOperationAble ( "0" );
                    } else {
                        zyIp.setOperationAble ( "1" );
                    }
                    String cinemaId = zyEs.getZyCinema () != null ? zyEs.getZyCinema ().getId () : "";
//					ZyContactsEntity zyContact = zyInspectionPlanService.queryCinemaInspectionContact(cinemaId);
                    zyIp.setZyCmIpCt ( ipCtsMap.get ( cinemaId ) );
                }
            }
            TagUtil.datagrid ( response, dataGrid );
        } catch (Exception e) {
            throw new BusinessException ( e.getMessage () );
        }
    }

    /**
     * 首页代办 - 第三方区域工程师 任务列表 - datagrid
     */
    @RequestMapping(params = "aegAssignEgListOfHomePageTask")
    public ModelAndView aegAssignEgListOfHomePageTask(HttpServletRequest request) {
        String optRule = StaticValue.DIC_PLAN_STATE_THIRDPARTY_ASSIGNED + ",";
        optRule += StaticValue.DIC_PLAN_STATE_ENGINEER_REFUSED;
        request.setAttribute ( "optRule", optRule );
        request.setAttribute ( "homePageType", oConvertUtils.getString ( request.getParameter ( "homePageType" ) ) );
        return new ModelAndView ( "com/zybk/zy_inspection_plan/zyAegAssignEgListOfHomePageTask" );
    }

    /**
     * 首页代办 - 第三方区域工程师 任务列表 - datagrid
     */
    @RequestMapping(params = "datagridOfAegAssignEgOfHomePageTask")
    @ResponseBody
    public void aegAssignEgListOfHomePageTask(ZyInspectionPlanEntity zyInspectionPlan, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
        CriteriaQuery cq = new CriteriaQuery ( ZyInspectionPlanEntity.class, dataGrid );
        cq.createAlias ( "areaEngineer.tsBaseUser", "areaEngineer_tsBaseUser" );
        org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql ( cq, zyInspectionPlan, request.getParameterMap () );
        try {
            TSUser user = ResourceUtil.getSessionUserName ();
            if (StringUtil.isNotEmpty ( request.getParameter ( "homePageType" ) )) {
                String homePageType = request.getParameter ( "homePageType" );
                if (homePageType.equals ( "tae_ipHadSend" )) {
                    ZyEngineerEntity eg = systemService.findUniqueByProperty ( ZyEngineerEntity.class, "tsBaseUser.id", user.getId () );
                    List<String> statesList = new ArrayList<String> ();
                    statesList.add ( StaticValue.DIC_PLAN_STATE_THIRDPARTY_ASSIGNED );
                    statesList.add ( StaticValue.DIC_PLAN_STATE_ENGINEER_REFUSED );
                    cq.add ( Restrictions.eq ( "areaEngineer.id", null != eg ? eg.getId () : "" ) );//如果工程师没有关系统用户，此处查询结果为空。（正常不可能出现这种情况）
                    cq.add ( Restrictions.in ( "state", statesList ) );
                }
            }
            cq.add ();
            this.zyInspectionPlanService.getDataGridReturn ( cq, true );
            Map<String, ZyContactsEntity> ipCtsMap = zyInspectionPlanService.queryCinemaIpContactsMap ();
            for (ZyInspectionPlanEntity zyIp : (List<ZyInspectionPlanEntity>) dataGrid.getResults ()) {
                if (zyIp != null) {
                    //设置省市 同时 显示
                    ZyEquipmentSpareEntity zyEs = zyIp.getEquipmentSpare ();
                    String tsTerritoryVal = "";
                    if (zyEs.getTsTerritory () != null && null != zyEs.getTsTerritory ().getTSTerritory ()) {
                        tsTerritoryVal = zyEs.getTsTerritory ().getTSTerritory ().getTerritoryName () + "," + zyEs.getTsTerritory ().getTerritoryName ();
                    } else if (zyEs.getTsTerritory () != null) {
                        tsTerritoryVal = zyEs.getTsTerritory ().getTerritoryName ();
                    }
                    zyIp.setTsTerritoryVal ( tsTerritoryVal );
					/*//设置计划服务时间 开始 结束同时显示
					if(zyIp.getOrderBeginTime() != null && zyIp.getOrderEndTime() != null){
						zyIp.setOrderBeginToEndVal(DataUtils.date2Str(zyIp.getOrderBeginTime(), new SimpleDateFormat("yyyy-MM-dd")) + " / " +
								DataUtils.date2Str(zyIp.getOrderEndTime(), new SimpleDateFormat("yyyy-MM-dd")) );
					}*/
                    String cinemaId = zyEs.getZyCinema () != null ? zyEs.getZyCinema ().getId () : "";
//					ZyContactsEntity zyContact = zyInspectionPlanService.queryCinemaInspectionContact(cinemaId);
                    zyIp.setZyCmIpCt ( ipCtsMap.get ( cinemaId ) );
                }
            }
        } catch (Exception e) {
            throw new BusinessException ( e.getMessage () );
        }
        TagUtil.datagrid ( response, dataGrid );
    }

    /**
     * 首页代办 - 工程师 任务列表 - datagrid
     */
    @RequestMapping(params = "egIpListOfHomePageTask")
    public ModelAndView egIpListOfHomePageTask(HttpServletRequest request) {
        String homePageType = oConvertUtils.getString ( request.getParameter ( "homePageType" ) );
        request.setAttribute ( "homePageType", homePageType );
        request.setAttribute ( "reportRules", StaticValue.DIC_PLAN_STATE_ENGINEER_IN_IMPLEMENT );
        return new ModelAndView ( "com/zybk/zy_inspection_plan/zyEgIpListOfHomePageTask" );
    }

    /**
     * 首页代办 - 工程师 任务列表 - datagrid
     */
    @RequestMapping(params = "egIpListDatagridOfHomePageTask")
    public void egIpListDatagridOfHomePageTask(ZyInspectionPlanEntity zyInspectionPlan, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
        CriteriaQuery cq = new CriteriaQuery ( ZyInspectionPlanEntity.class, dataGrid );
        //查询条件组装器
        org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql ( cq, zyInspectionPlan, request.getParameterMap () );
        try {
            //如果是从首页跳转过来
            if (StringUtil.isNotEmpty ( request.getParameter ( "homePageType" ) )) {
                String homePageType = request.getParameter ( "homePageType" );
                TSUser user = ResourceUtil.getSessionUserName ();
                ZyEngineerEntity engineer = systemService.findUniqueByProperty ( ZyEngineerEntity.class, "tsBaseUser.id", user.getId () );
                String engineerId = engineer.getId ();
                String overTimeStates = "'" + StaticValue.DIC_PLAN_STATE_INSPECTION_COMPLETE + "',";
                overTimeStates += "'" + StaticValue.DIC_PLAN_STATE_INSPECTION_CANCEL + "'";
                if (homePageType.equals ( "te_ipTodo" )) {
					/*未接单巡检计划数量：分配给本人的巡检计划中没有接受的数量。*/
                    cq.add ( Restrictions.eq ( "engineer.id", engineerId ) );
                    //1：巡检单位中 有区域工程师
                    List<String> statesHadAreaEg = new ArrayList<String> ();
                    statesHadAreaEg.add ( StaticValue.DIC_PLAN_STATE_ENGINEER_REFUSED );
                    statesHadAreaEg.add ( StaticValue.DIC_PLAN_STATE_AREA_ENGINEER_ASSIGNED );
                    //2：没有区域工程师
                    List<String> statesHadNotAreaEg = new ArrayList<String> ();
                    statesHadNotAreaEg.add ( StaticValue.DIC_PLAN_STATE_ENGINEER_REFUSED );
                    statesHadNotAreaEg.add ( StaticValue.DIC_PLAN_STATE_THIRDPARTY_ASSIGNED );

                    cq.or ( Restrictions.and ( Restrictions.eq ( "companyHadAreaEg", "1" ), Restrictions.in ( "state", statesHadAreaEg ) ),
                            Restrictions.and ( Restrictions.eq ( "companyHadAreaEg", "0" ), Restrictions.in ( "state", statesHadNotAreaEg ) ) );
                } else if (homePageType.equals ( "te_ipDidnotComplete" )) {
					/*未完成巡检计划数量：本人接受的巡检计划中没有提交巡检报告的数量。*/
                    List<String> statesDidnotComplete = new ArrayList<String> ();
                    statesDidnotComplete.add ( StaticValue.DIC_PLAN_STATE_ENGINEER_ASSIGNED );
                    statesDidnotComplete.add ( StaticValue.DIC_PLAN_STATE_ENGINEER_IN_IMPLEMENT );
                    cq.add ( Restrictions.eq ( "engineer.id", engineerId ) );
                    cq.add ( Restrictions.in ( "state", statesDidnotComplete ) );
                } else if (homePageType.equals ( "te_ipOverTime" )) {
					/*超时任务提醒：第三方工程师接受的巡检计划中在指定的预约上门时间48小时后还未提交巡检报告的巡检计划的数量*/
                    List<Map<String, Object>> idsMap =
                            systemService.findForJdbc ( "SELECT id FROM zy_inspection_plan WHERE engineer = ? AND state not in (" + overTimeStates + ") AND TIMESTAMPDIFF(HOUR ,engineer_order_time,NOW()) > 48 ", engineerId );
                    List<String> ids = new ArrayList<String> ();
                    for (Map<String, Object> map : idsMap) {
                        ids.add ( map.get ( "id" ).toString () );
                    }
                    cq.add ( Restrictions.in ( "id", ids ) );
                } else if (homePageType.equals ( "te_ipTomorrow" )) {
					/*次日巡检任务提醒：本人接受的巡检计划中预约上门时间为第二天还未提交巡检报告的巡检计划的数量*/
                    List<Map<String, Object>> idsMap =
                            systemService.findForJdbc ( "SELECT id FROM zy_inspection_plan WHERE engineer = ? AND state not in (" + overTimeStates + ") AND TIMESTAMPDIFF(DAY ,NOW(),engineer_order_time) = 0 ", engineerId );
                    List<String> ids = new ArrayList<String> ();
                    for (Map<String, Object> map : idsMap) {
                        ids.add ( map.get ( "id" ).toString () );
                    }
                    cq.add ( Restrictions.in ( "id", ids ) );
                }
            }
            cq.add ();
            this.zyInspectionPlanService.getDataGridReturn ( cq, true );
            Map<String, ZyContactsEntity> ipCtsMap = zyInspectionPlanService.queryCinemaIpContactsMap ();
            for (ZyInspectionPlanEntity zyIp : (List<ZyInspectionPlanEntity>) dataGrid.getResults ()) {
                if (zyIp != null) {
                    //设置省市 同时 显示
                    ZyEquipmentSpareEntity zyEs = zyIp.getEquipmentSpare ();
                    String tsTerritoryVal = "";
                    if (zyEs.getTsTerritory () != null && null != zyEs.getTsTerritory ().getTSTerritory ()) {
                        tsTerritoryVal = zyEs.getTsTerritory ().getTSTerritory ().getTerritoryName () + "," + zyEs.getTsTerritory ().getTerritoryName ();
                    } else if (zyEs.getTsTerritory () != null) {
                        tsTerritoryVal = zyEs.getTsTerritory ().getTerritoryName ();
                    }
                    zyIp.setTsTerritoryVal ( tsTerritoryVal );
					/*//设置计划服务时间 开始 结束同时显示
					if(zyIp.getOrderBeginTime() != null && zyIp.getOrderEndTime() != null){
						zyIp.setOrderBeginToEndVal(DataUtils.date2Str(zyIp.getOrderBeginTime(), new SimpleDateFormat("yyyy-MM-dd")) + " / " +
								DataUtils.date2Str(zyIp.getOrderEndTime(), new SimpleDateFormat("yyyy-MM-dd")) );
					}*/
                    String cinemaId = zyEs.getZyCinema () != null ? zyEs.getZyCinema ().getId () : "";
//					ZyContactsEntity zyContact = zyInspectionPlanService.queryCinemaInspectionContact(cinemaId);
                    zyIp.setZyCmIpCt ( ipCtsMap.get ( cinemaId ) );
                }
            }
        } catch (Exception e) {
            throw new BusinessException ( e.getMessage () );
        }
        TagUtil.datagrid ( response, dataGrid );
    }

    /**
     * 巡检问题分析报表 - 点击数字跳转
     */
    @RequestMapping(params = "ipListOfIpProblemAnalysisReport")
    public ModelAndView ipListOfIpProblemAnalysisReport(HttpServletRequest request) {
        String paramsString = "";
        String year = oConvertUtils.getString ( request.getParameter ( "year" ) );
        String month = oConvertUtils.getString ( request.getParameter ( "month" ) );
        String exType = oConvertUtils.getString ( request.getParameter ( "exType" ) );
        String ttId = oConvertUtils.getString ( request.getParameter ( "ttId" ) );
        String departIds = oConvertUtils.getString ( request.getParameter ( "departIds" ) );
        String esTypes = oConvertUtils.getString ( request.getParameter ( "esTypes" ) );

        String ipEndTimeYear = oConvertUtils.getString ( request.getParameter ( "ipEndTimeYear" ) );
        String ipEndTimeMonth = oConvertUtils.getString ( request.getParameter ( "ipEndTimeMonth" ) );
        if (StringUtil.isNotEmpty ( year )) {//year是基础查询条件，这里根据year 和 ipEndTimeYear 来区分
            paramsString = "year=" + year + "&month=" + month + "&exType=" + exType + "&ttId=" + ttId+"&departIds=" + departIds+"&esTypes=" + esTypes;
        } else if (StringUtil.isNotEmpty ( ipEndTimeYear )) {
            paramsString = "&ipEndTimeYear=" + ipEndTimeYear + "&ipEndTimeMonth=" + ipEndTimeMonth;
        }
        request.setAttribute ( "params", paramsString );
        String optRule = StaticValue.DIC_PLAN_STATE_TODO + ",";
//        optRule += StaticValue.DIC_PLAN_STATE_THIRDPARTY_REFUSED;
        request.setAttribute ( "optRule", optRule );
        return new ModelAndView ( "com/zybk/zy_inspection_plan/zyIpListOfIpProblemAnalysisReport" );
    }

    /**
     * 巡检问题分析报表 - 点击数字跳转  - datagrid
     */
    @RequestMapping(params = "datagridOfIpListOfIpProblemAnalysisReport")
    public void datagridOfIpListOfIpProblemAnalysisReport(ZyInspectionPlanEntity zyInspectionPlan, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
        CriteriaQuery cq = new CriteriaQuery ( ZyInspectionPlanEntity.class, dataGrid );
        //查询条件组装器
        org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql ( cq, zyInspectionPlan, request.getParameterMap () );
        try {
			/*//从巡检问题分析报表跳转过来的
			String year = request.getParameter("year");//年份
			String month = request.getParameter("month");//月份
			String exType = request.getParameter("exType");//异常类型
			String ttId = request.getParameter("ttId");//省份Id

			String ipEndTimeYear = oConvertUtils.getString(request.getParameter("ipEndTimeYear"));
			String ipEndTimeMonth = oConvertUtils.getString(request.getParameter("ipEndTimeMonth"));

			List<String> planIds = new ArrayList<String>();
			if(StringUtil.isNotEmpty(year)){//year是基础查询条件，这里根据year 和 ipEndTimeYear 来区分
				planIds = zyInspectionPlanService.getPlanIdsByReportExceptionConditions(year,month,exType,ttId);
			}else if(StringUtil.isNotEmpty(ipEndTimeYear)){
				planIds = zyInspectionPlanService.getPlanIdsByIrExReportConditions(ipEndTimeYear,ipEndTimeMonth);
			}*/

            zyInspectionReportServiceI.queryDataForIpListOfIpProblemAnalysisReport ( request, dataGrid );
			/*if(planIds.size() == 0){
				planIds.add("");
			}
			cq.add(Restrictions.in("id", planIds));
			this.zyInspectionPlanService.getDataGridReturn(cq, true);
			for (ZyInspectionPlanEntity  zyIp: (List<ZyInspectionPlanEntity>)dataGrid.getResults()) {
				if(zyIp != null){
					String tsTerritoryVal = "";
					if(zyIp.getEquipmentSpare().getTsTerritory() != null && null != zyIp.getEquipmentSpare().getTsTerritory().getTSTerritory()){
						tsTerritoryVal = zyIp.getEquipmentSpare().getTsTerritory().getTSTerritory().getTerritoryName() + "," + zyIp.getEquipmentSpare().getTsTerritory().getTerritoryName();
					}else if(zyIp.getEquipmentSpare().getTsTerritory() != null){
						tsTerritoryVal = zyIp.getEquipmentSpare().getTsTerritory().getTerritoryName();
					}
					zyIp.setTsTerritoryVal(tsTerritoryVal);
				}
			}*/
        } catch (Exception e) {
            throw new BusinessException ( e.getMessage () );
        }
        TagUtil.datagrid ( response, dataGrid );
    }

    /**
     * 首页 快速查询巡检计划 跳转
     */
    @RequestMapping(params = "homePageInspectionPlanList")
    public ModelAndView homePageInspectionPlanList(HttpServletRequest request) {
        String planId = oConvertUtils.getString ( request.getParameter ( "planId" ) );
        request.setAttribute ( "planId", planId );
        return new ModelAndView ( "com/zybk/zy_inspection_plan/zySendInspectionPlanListOnlyRead" );
    }

    /**
     * 首页 快速查询巡检计划 datagrid
     */
    @RequestMapping(params = "datagridOfHomePage")
    public void datagridOfHomePage(ZyInspectionPlanEntity zyInspectionPlan, HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
        CriteriaQuery cq = new CriteriaQuery ( ZyInspectionPlanEntity.class, dataGrid );
        try {
            String sn = request.getParameter ( "sn" );
            if (StringUtil.isNotEmpty ( sn )) {
                List<ZyEquipmentSpareEntity> zyEquipmentSpare = systemService.findByProperty ( ZyEquipmentSpareEntity.class, "sn", sn );
                cq.eq ( "equipmentSpare", zyEquipmentSpare.get ( 0 ) );
            }
            org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql ( cq, zyInspectionPlan, request.getParameterMap () );
        } catch (Exception e) {
            throw new BusinessException ( e.getMessage () );
        }
        cq.add ();
        this.zyInspectionPlanService.getDataGridReturn ( cq, true );
        TagUtil.datagrid ( response, dataGrid );
    }

    /**
     * @author ZhangYunlong
     * 2016-4-1 下午5:07:29
     * Description	设备详情页巡检记录列表
     */
    @RequestMapping(params = "datagridOfEquipmentDetails")
    public void datagridOfEquipmentDetails(HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
        String esSn = request.getParameter ( "sn" );
        List<Map<String, Object>> results = new ArrayList<Map<String, Object>> ();
        if (null != esSn && !esSn.equals ( "" )) {
            results = zyInspectionPlanService.queryIpForEsDetailsPage ( esSn );
        }

        dataGrid.setResults ( results );

        TagUtil.datagrid ( response, dataGrid );
    }

    /**
     * @author xiul
     * 2016-5-19 下午4:33:17
     * Description 巡检计划导出
     */
    @ResponseBody
    @RequestMapping(params = "exportInspectionPlan")
    public void exportInspectionPlan(HttpServletRequest request, HttpServletResponse response) {
        zyInspectionPlanService.exportInspectionPlan ( request, response );

    }

    /**
     * @author xiul
     * 2016-9-21 下午2:35:24
     * Description 跳转 - 客户服务满意度报表(服务评价报表)
     */
    @RequestMapping(params = "goIpEvaluateReport")
    public ModelAndView goIpEvaluateReport(HttpServletRequest req) {
        List<String> years = zyCommonService.queryYearsInIp ();
        req.setAttribute ( "years", years );
        List<String> wxYears = zyCommonService.queryYearsInIpForRepair ();
        req.setAttribute ( "wxYears", wxYears );
        TSUser user = ResourceUtil.getSessionUserName ();
        if (userService.hasRoles ( user.getUserName (), new String[]{StaticValue.RULE_CODE_THIRDPARTY_HEADER, StaticValue.RULE_CODE_THIRDPARTY_MANAGER} )) {
            req.setAttribute ( "tpRoleUser", true );
            req.setAttribute ( "userDpId", user.getCurrentDepart ().getId () );
            req.setAttribute ( "userDpCode", user.getCurrentDepart ().getOrgCode () );
        }
        return new ModelAndView ( "com/zybk/zy_inspection_plan/zyInpsectionEvaluateReport" );
    }

    /**
     * @param year      年份
     * @param ipCompany 巡检单位
     * @author xiul
     * 2016-9-21 下午2:31:51
     * Description 客户服务满意度报表 - 第三方满意度
     */
    @ResponseBody
    @RequestMapping(params = "queryIpEvaluateReportDataOfTp")
    public AjaxJson queryIpEvaluateReportDataOfTp(
            @RequestParam(value = "year") String year,
            @RequestParam(value = "ipCompany", required = false) String ipCompany,
            @RequestParam(value = "egIds", required = false) String egIds
    ) {
        AjaxJson j = new AjaxJson ();
        try {
            List<List<String>> ipEvaluateReportDataOfTp = cbsInspectionEvaluateServiceI.queryIpEvaluateReportDataOfTp ( year, ipCompany, egIds );
            j.setObj ( ipEvaluateReportDataOfTp );
        } catch (Exception e) {
            j.setSuccess ( false );
            j.setMsg ( "报表数据查询失败" );
            e.printStackTrace ();
        }
        return j;
    }


    /**
     * @param year      年份
     * @param ipCompany 维修单位
     * @author mhg
     * 2018-6-28
     * Description 客户服务满意度报表 - 维修第三方满意度
     */
    @ResponseBody
    @RequestMapping(params = "queryIpRepairEvaluateReportDataOfTp")
    public AjaxJson queryIpRepairEvaluateReportDataOfTp(
            @RequestParam(value = "year") String year,
            @RequestParam(value = "ipCompany", required = false) String ipCompany,
            @RequestParam(value = "egIds", required = false) String egIds
    ) {
        AjaxJson j = new AjaxJson ();
        try {
            List<List<String>> ipRepairEvaluateReportDataOfTp = cbsInspectionEvaluateServiceI.queryIpRepairEvaluateReportDataOfTp ( year, ipCompany, egIds );
            j.setObj ( ipRepairEvaluateReportDataOfTp );
        } catch (Exception e) {
            j.setSuccess ( false );
            j.setMsg ( "报表数据查询失败" );
            e.printStackTrace ();
        }
        return j;
    }

    /**
     * @param year      年份
     * @param ipCompany 巡检单位
     * @author xiul
     * 2016-9-21 下午2:31:51
     * Description 客户服务满意度报表 - 对工程师的满意度
     */
    @ResponseBody
    @RequestMapping(params = "queryIpEvaluateReportDataOfEg")
    public AjaxJson queryIpEvaluateReportDataOfEg(@RequestParam(value = "year") String year,
                                                  @RequestParam(value = "ipCompany", required = false) String ipCompany,
                                                  @RequestParam(value = "egIds", required = false) String egIds) {
        AjaxJson j = new AjaxJson ();
        try {
            cbsInspectionEvaluateServiceI.queryIpEvaluateReportDataOfEg ( j, year, ipCompany, egIds );
        } catch (Exception e) {
            j.setSuccess ( false );
            j.setMsg ( "报表数据查询失败" );
            e.printStackTrace ();
        }
        return j;
    }

    /**
     * @param year      年份
     * @param ipCompany 巡检单位
     * @author mhg
     * 2018-6-28
     * Description 客户服务满意度报表 - 对维修工程师的满意度
     */
    @ResponseBody
    @RequestMapping(params = "queryIpRepairEvaluateReportDataOfEg")
    public AjaxJson queryIpRepairEvaluateReportDataOfEg(@RequestParam(value = "year") String year,
                                                  @RequestParam(value = "ipCompany", required = false) String ipCompany,
                                                  @RequestParam(value = "egIds", required = false) String egIds) {
        AjaxJson j = new AjaxJson ();
        try {
            cbsInspectionEvaluateServiceI.queryIpRepairEvaluateReportDataOfEg ( j, year, ipCompany, egIds );
        } catch (Exception e) {
            j.setSuccess ( false );
            j.setMsg ( "报表数据查询失败" );
            e.printStackTrace ();
        }
        return j;
    }

    /**
     * ----begin 测试 用 ----
     */
    @Autowired
    private ZyTimeTaskCheckReportService zyCheck;
    @Autowired
    private ZyTimeTaskOfInspectionPlanService zyTimeTaskOfInspectionPlanService;

    @ResponseBody
    @RequestMapping(params = "autoGenerateInspectionPlan")
    public AjaxJson autoGenerateInspectionPlan() {
        AjaxJson j = new AjaxJson ();
        try {
            zyTimeTaskOfInspectionPlanService.AutoGenerateInspectionPlan ();
        } catch (Exception e) {
            e.printStackTrace ();
        }
        return j;
    }

    @ResponseBody
    @RequestMapping(params = "zyRecordImport")
    public AjaxJson zyRecordImport() {
        AjaxJson j = new AjaxJson ();
        try {

            zyTimeTaskForInstallRecordSevice.zyRecordImport ();
        } catch (Exception e) {
            e.printStackTrace ();
        }
        return j;
    }


    @ResponseBody
    @RequestMapping(params = "getInfoFromLastYearIps")
    public AjaxJson getInfoFromLastYearIps() {
        AjaxJson j = new AjaxJson ();
        try {
            zyTimeTaskOfInspectionPlanService.getInfoFromLastYearIps ();
        } catch (Exception e) {
            e.printStackTrace ();
        }
        return j;
    }

    @ResponseBody
    @RequestMapping(params = "checkReport")
    public AjaxJson checkReport() {
        AjaxJson j = new AjaxJson ();
        try {
            zyCheck.zyCheckInspectionPlanReport ();
        } catch (Exception e) {
            e.printStackTrace ();
        }
        return j;
    }

    @ResponseBody
    @RequestMapping(params = "timeTaskOfCheckPlanOfEngineer")
    public AjaxJson timeTaskOfCheckPlanOfEngineer() {
        AjaxJson j = new AjaxJson ();
        try {
            zyCheck.timeTaskOfCheckPlanOfEngineer ();
        } catch (Exception e) {
            e.printStackTrace ();
        }
        return j;
    }
    /**----end of 测试 用 ----*/


    /**
     * @author xiul
     * 2016-8-24 下午2:53:02
     * Description APP - 第三方上午 or 工程师 or 区域工程师 查询巡检计划代办数量
     */
    @ResponseBody
    @RequestMapping(params = "queryAppAegOrEgTodoIps")
    public AjaxJson queryAppAegOrEgTodoIps(HttpServletRequest req) {
        AjaxJson j = new AjaxJson ();
        j.setObj ( zyInspectionPlanService.queryAppAegOrEgTodoIps () );
        return j;
    }


    /**
     * @author xiul
     * 2016-8-11 下午9:13:26
     * Description APP - 第三方巡检列表数据请求
     */
    @ResponseBody
    @RequestMapping(params = "queryAppIpTpList")
    public AjaxJson queryAppIpTpList(HttpServletRequest req) {
        AjaxJson j = new AjaxJson ();
        Map<String, Object> rtMap = new HashMap<String, Object> ();
        int type = oConvertUtils.getInt ( oConvertUtils.getString ( req.getParameter ( "type" ) ) );
        String area = oConvertUtils.getString ( req.getParameter ( "area" ) );
        String planYear = oConvertUtils.getString ( req.getParameter ( "planYear" ) );
        String planMonth = oConvertUtils.getString ( req.getParameter ( "planMonth" ) );
        String esSn = oConvertUtils.getString ( req.getParameter ( "esSn" ) );
        String cmId = oConvertUtils.getString ( req.getParameter ( "cmId" ) );
        Map<String, Object> ipTpListMap = zyInspectionPlanService.queryAppIpTpList ( type, area, planYear, planMonth, esSn, cmId );
        rtMap.put ( "ipTpListMap", ipTpListMap );
        j.setAttributes ( rtMap );
        return j;
    }

    /**
     * @author xiul
     * 2016-8-9 下午2:20:31
     * Description APP - 第三方 负责人巡检计划详细页
     */
    @ResponseBody
    @RequestMapping(params = "appIpDetailOfTp")
    public AjaxJson appIpDetailOfTp(HttpServletRequest req) {
        AjaxJson j = new AjaxJson ();
        String ipId = oConvertUtils.getString ( req.getParameter ( "ipId" ) );
        if (!ipId.equals ( "" )) {
            j.setAttributes ( zyInspectionPlanService.queryIpDetailOfTP ( ipId ) );
        }
        return j;
    }

    /**
     * @author xiul
     * 2016-8-9 下午2:20:31
     * Description APP - 第三方 负责人分配巡检计划 页面数据加载
     */
    @ResponseBody
    @RequestMapping(params = "goAppTpSendIp")
    public AjaxJson goAppTpSendIp(HttpServletRequest request) {
        AjaxJson j = new AjaxJson ();
        Map<String, Object> rsMap = new HashMap<String, Object> ();
        String planIds = oConvertUtils.getString ( request.getParameter ( "planIds" ) );
        rsMap.put ( "planIds", planIds );
        String[] ids = planIds.split ( "," );
        if (ids != null && ids.length > 0) {
            if (StringUtil.isNotEmpty ( ids[0] )) {
                ZyInspectionPlanEntity plan = zyInspectionPlanService.get ( ZyInspectionPlanEntity.class, ids[0].toString () );
                rsMap.put ( "company", plan.getCompany () );
                rsMap.put ( "ipCount", ids.length );
            }
        }
        j.setAttributes ( rsMap );
        return j;
    }

    /**
     * @author xiul
     * 2016-8-15 下午7:21:45
     * Description APP - 巡检计划列表页 搜索
     */
    @ResponseBody
    @RequestMapping(params = "queryEsOrCm")
    public AjaxJson queryEsOrCm(HttpServletRequest req) {
        AjaxJson j = new AjaxJson ();
        j.setObj ( zyInspectionPlanService.queryEsOrCm ( req ) );
        return j;
    }

    /**
     * @author xiul
     * 2016-8-15 下午8:31:35
     * Description APP - 第三方分派巡检计划页 - 查询工程师
     */
    @ResponseBody
    @RequestMapping(params = "queryEngineerForAppSendIp")
    public AjaxJson queryEngineerForAppSendIp(HttpServletRequest req) {
        AjaxJson j = new AjaxJson ();
        String planIds = oConvertUtils.getString ( req.getParameter ( "planIds" ) );
        String company = oConvertUtils.getString ( req.getParameter ( "company" ) );
        DataGrid dataGrid = new DataGrid ();
        zyInspectionPlanService.queryDatagridResultForChooseEngineers ( req, dataGrid, company, planIds );
        j.setObj ( dataGrid.getResults () );
        return j;
    }

    /**
     * @author xiul
     * 2016-9-2 下午3:03:26
     * Description APP - 查询工程师 以及 工程师 未处理，进行中 等数据
     */
    @ResponseBody
    @RequestMapping(params = "queryEgTasks")
    public AjaxJson queryEgTasks(HttpServletRequest req) {
        AjaxJson j = new AjaxJson ();
        String egId = oConvertUtils.getString ( req.getParameter ( "egId" ) );
        Map<String, Object> rsMap = zyInspectionPlanService.queryEgTasks ( egId );
        j.setAttributes ( rsMap );
        return j;
    }

    /**
     * @author xiul
     * 2016-8-16 下午1:22:54
     * Description APP - 第三方分派工程师 (之所以没用pc端的分配方法，因为 在绑定时间时 会有问题)
     */
    @ResponseBody
    @RequestMapping(params = "appTpSendIp")
    public AjaxJson appTpSendIp(HttpServletRequest request, ZyInspectionPlanEntity zyInpInspectionPlanEntity) {
        AjaxJson j = new AjaxJson ();
        TSUser user = ResourceUtil.getSessionUserName ();
        String planIds = oConvertUtils.getString ( request.getParameter ( "planIds" ) );
        String orderBeginTime_str = oConvertUtils.getString ( request.getParameter ( "orderBeginTime_str" ) );
        String orderEndTime_str = oConvertUtils.getString ( request.getParameter ( "orderEndTime_str" ) );
        zyInpInspectionPlanEntity.setOrderBeginTime ( DateUtils.str2Date ( orderBeginTime_str, DateUtils.date_sdf ) );
        zyInpInspectionPlanEntity.setOrderEndTime ( DateUtils.str2Date ( orderEndTime_str, DateUtils.date_sdf ) );
        try {
            zyInspectionPlanService.doBatchAssignEngineer ( planIds, zyInpInspectionPlanEntity );
            CbsAppMessageEntity appMessage = new CbsAppMessageEntity ();
            String content = "您收到" + planIds.split ( "," ).length + "个新的巡检任务，可在“我的任务”中查看详情。";
            appMessage.setContent ( content );
            appMessage.setSender ( user.getId () );
            ZyEngineerEntity engineer = systemService.get ( ZyEngineerEntity.class, zyInpInspectionPlanEntity.getEngineer ().getId () );
            TSBaseUser baseUser = systemService.get ( TSBaseUser.class, engineer.getTsBaseUser ().getId () );
            appMessage.setReciver ( baseUser.getId () );
            appMessage.setState ( StaticValue.DIC_APP_MESSAGE_STATE_UNREAD );
            systemService.save ( appMessage );
            systemService.addLog ( "新增APP消息,接受方:" + baseUser.getId () + ",内容:" + content, Globals.Log_Leavel_INFO, Globals.log_type_SEND_EMAIL );
        } catch (Exception e) {
            e.printStackTrace ();
        }
        return j;
    }

    /**
     * @author xiul
     * 2016-8-16 下午12:53:27
     * Description APP - 设备变更申请页 - 影院查询
     */
    @ResponseBody
    @RequestMapping(params = "queryCmForAppEsChange")
    public AjaxJson queryCmForAppEsChange(HttpServletRequest req) {
        AjaxJson j = new AjaxJson ();
        List<Map<String, Object>> rsMap = zyInspectionPlanService.queryCmForAppEsChange ( req );
        j.setObj ( rsMap );
        return j;
    }

    /**
     * @author xiul
     * 2016-8-11 下午9:13:26
     * Description APP - 区域工程师巡检列表数据请求
     */
    @ResponseBody
    @RequestMapping(params = "queryAppIpAegList")
    public AjaxJson queryAppIpAegList(HttpServletRequest req) {
        AjaxJson j = new AjaxJson ();
        Map<String, Object> rtMap = new HashMap<String, Object> ();
        int type = oConvertUtils.getInt ( oConvertUtils.getString ( req.getParameter ( "type" ) ) );
        String area = oConvertUtils.getString ( req.getParameter ( "area" ) );
        String planYear = oConvertUtils.getString ( req.getParameter ( "planYear" ) );
        String planMonth = oConvertUtils.getString ( req.getParameter ( "planMonth" ) );
        String esSn = oConvertUtils.getString ( req.getParameter ( "esSn" ) );
        String cmId = oConvertUtils.getString ( req.getParameter ( "cmId" ) );
        Map<String, Object> ipAegListMap = zyInspectionPlanService.queryAppIpAegList ( type, area, planYear, planMonth, esSn, cmId );
        rtMap.put ( "ipAegListMap", ipAegListMap );
        j.setAttributes ( rtMap );
        return j;
    }

    /**
     * @author xiul
     * 2016-8-9 下午2:20:31
     * Description APP - 区域工程师 查询巡检计划详细
     */
    @ResponseBody
    @RequestMapping(params = "appIpDetailOfAeg")
    public AjaxJson appIpDetailOfAeg(HttpServletRequest req) {
        AjaxJson j = new AjaxJson ();
        String ipId = oConvertUtils.getString ( req.getParameter ( "ipId" ) );
        if (!ipId.equals ( "" )) {
            j.setAttributes ( zyInspectionPlanService.queryIpDetailOfAeg ( ipId ) );
        }
        return j;
    }

    /**
     * @author xiul
     * 2016-8-18 上午10:20:04
     * Description APP - 区域工程师 分派工程师页面数据加载
     */
    @ResponseBody
    @RequestMapping(params = "queryAegSendEg")
    public AjaxJson queryAegSendEg(HttpServletRequest request, String planIds) {
        AjaxJson j = new AjaxJson ();
        Map<String, Object> rsMap = new HashMap<String, Object> ();
        rsMap.put ( "planIds", planIds );
        String[] ids = planIds.split ( "," );
        if (ids != null && ids.length > 0) {
            ZyInspectionPlanEntity plan = zyInspectionPlanService.get ( ZyInspectionPlanEntity.class, ids[0].toString () );
            rsMap.put ( "orderBeginTime", DateUtils.date2Str ( plan.getOrderBeginTime (), DateUtils.date_sdf ) );
            rsMap.put ( "orderEndTime", DateUtils.date2Str ( plan.getOrderEndTime (), DateUtils.date_sdf ) );
            rsMap.put ( "company", plan.getCompany () );
            rsMap.put ( "ipCount", ids.length );
        }
        j.setAttributes ( rsMap );
        return j;
    }

    /**
     * @author xiul
     * 2016-8-18 上午10:35:05
     * Description APP - 区域工程师 分派 工程师 - 查询工程师
     */
    @ResponseBody
    @RequestMapping(params = "queryEngineerForAppAegSendIp")
    public AjaxJson queryEngineerForAppAegSendIp(HttpServletRequest req) {
        AjaxJson j = new AjaxJson ();
        //String planIds = oConvertUtils.getString(req.getParameter("planIds"));
        //String orgCode = oConvertUtils.getString(req.getParameter("company"));
        //DataGrid dataGrid = new DataGrid();
        //zyInspectionPlanService.queryDatagridResultForAreaChooseEngineers(req, dataGrid,orgCode,planIds);
        //j.setObj(dataGrid.getResults());

        zyInspectionPlanService.queryEngineerForAppAegSendIp ( req, j );
        return j;
    }

    /**
     * @author xiul
     * 2016-8-18 下午9:13:26
     * Description APP - 工程师巡检列表数据请求
     */
    @ResponseBody
    @RequestMapping(params = "queryAppIpEgList")
    public AjaxJson queryAppIpEgList(HttpServletRequest req) {
        AjaxJson j = new AjaxJson ();
        Map<String, Object> rtMap = new HashMap<String, Object> ();
        int type = oConvertUtils.getInt ( oConvertUtils.getString ( req.getParameter ( "type" ) ) );
        String area = oConvertUtils.getString ( req.getParameter ( "area" ) );
        String planYear = oConvertUtils.getString ( req.getParameter ( "planYear" ) );
        String planMonth = oConvertUtils.getString ( req.getParameter ( "planMonth" ) );
        String esSn = oConvertUtils.getString ( req.getParameter ( "esSn" ) );
        String cmId = oConvertUtils.getString ( req.getParameter ( "cmId" ) );
        Map<String, Object> ipEgListMap = zyInspectionPlanService.queryAppIpEgList ( type, area, planYear, planMonth, esSn, cmId );
        rtMap.put ( "ipEgListMap", ipEgListMap );
        j.setAttributes ( rtMap );
        return j;
    }

    /**
     * @author xiul
     * 2016-8-19 上午10:57:53
     * Description APP - 工程师接受任务
     */
    @ResponseBody
    @RequestMapping(params = "appEgAcceptIp")
    public AjaxJson appEgAcceptIp(HttpServletRequest request) {
        AjaxJson j = new AjaxJson ();
        boolean flag = true;
        message = "接受成功";
        try {
            String planIds = oConvertUtils.getString ( request.getParameter ( "planIds" ) );
            String engineerOrderTime = oConvertUtils.getString ( request.getParameter ( "engineerOrderTime" ) );
            if (!planIds.replace ( ",", "" ).equals ( "" )) {
                zyInspectionPlanService.doBatchEngineerAssignPlan ( planIds );
                for (String id : planIds.split ( "," )) {
                    zyInspectionPlanService.doEngineerUpdateIp ( id, engineerOrderTime, "" );
                }
            } else {
                flag = false;
                message = "没有选择巡检计划";
            }
        } catch (Exception e) {
            e.printStackTrace ();
            flag = false;
            message = "接受失败";
        }
        j.setMsg ( message );
        j.setSuccess ( flag );
        return j;
    }

    /**
     * @author xiul
     * 2016-8-19 下午2:06:32
     * Description APP - 工程师 签到
     */
    @ResponseBody
    @RequestMapping(params = "appEgSignIn")
    public AjaxJson appEgSignIn(HttpServletRequest req) {
        AjaxJson j = new AjaxJson ();
        zyInspectionPlanService.appEgSignIn ( req, j );
        return j;
    }

    /**
     * @author xiul
     * 2016-8-18 下午9:13:26
     * Description APP - 工程师签到 后显示的详情页数据加载
     */
    @ResponseBody
    @RequestMapping(params = "appEgSignInDetial")
    public AjaxJson appEgSignInDetial(HttpServletRequest req) {
        AjaxJson j = new AjaxJson ();
        j.setAttributes ( zyInspectionPlanService.appEgSignInDetial ( req ) );
        return j;
    }

    /**
     * @author xiul
     * 2016-8-9 下午2:20:31
     * Description APP - 工程师 巡检计划详细页
     */
    @ResponseBody
    @RequestMapping(params = "appIpDetailOfEg")
    public AjaxJson appIpDetailOfEg(HttpServletRequest req) {
        AjaxJson j = new AjaxJson ();
        String ipId = oConvertUtils.getString ( req.getParameter ( "ipId" ) );
        if (!ipId.equals ( "" )) {
            StringBuffer sql = new StringBuffer ();
            sql.append ( " SELECT " );
//            sql.append ( " 	ei.ID AS id, CONCAT(ei.item, scope) AS item " ); //18/6/7 修改，不取字段scope
            sql.append ( " 	ei.ID AS id, ei.item AS item " );
            sql.append ( " FROM " );
            sql.append ( " 	zy_es_item ei " );
            sql.append ( " LEFT JOIN zy_equipment_type et ON et.id = ei.type " );
            sql.append ( " WHERE " );
            sql.append ( " 	et.type_desc = ? " );
            //巡检报告备件
            Map<String, Object> rsMap = new HashMap<String, Object> ();//map 中的key和页面中的name对应方便循环
            rsMap.put ( "engItemId", systemService.findForJdbc ( sql.toString (), "ENG" ) );
            rsMap.put ( "tiIcpItemId", systemService.findForJdbc ( sql.toString (), "TI/ICP" ) );
            rsMap.put ( "lpsItemId", systemService.findForJdbc ( sql.toString (), "LPS" ) );
            rsMap.put ( "ldmItemId", systemService.findForJdbc ( sql.toString (), "LDM" ) );
            rsMap.put ( "enigmaItemId", systemService.findForJdbc ( sql.toString (), "Enigma" ) );
            rsMap.put ( "controlerItemId", systemService.findForJdbc ( sql.toString (), "Controller" ) );
            rsMap.put ( "smpsItemId", systemService.findForJdbc ( sql.toString (), "SMPS" ) );
            rsMap.put ( "touchItemId", systemService.findForJdbc ( sql.toString (), "触摸屏" ) );
            //服务器品牌。TMS品牌
            rsMap.put ( "tmsBrandId", zyEquipmentTypeService.queryEsTypeByPTypeDescAndPPTypeDesc ( req, "服务器", "设备" ) );
            rsMap.put ( "serverBrandId", zyEquipmentTypeService.queryEsTypeByPTypeDescAndPPTypeDesc ( req, null, "服务器" ) );
            j.setObj ( rsMap );
            /////要传值到页面 放到下边的map
            Map<String, Object> attMap = new HashMap<String, Object> ();
            attMap.put ( "ipDetailMap", zyInspectionPlanService.queryIpDetailOfEg ( ipId ) );
            attMap.put ( "uuid", UUID.randomUUID ().toString ().replace ( "-", "" ) );
            j.setAttributes ( attMap );
        }
        return j;
    }

    /**
     * 根据巡检计划查询巡检报告的类型供app判断显示不同的内容
     *
     * @param req
     * @return
     */
    @ResponseBody
    @RequestMapping(params = "queryReportType")
    public AjaxJson queryReportType(HttpServletRequest req) {
        AjaxJson j = new AjaxJson ();
        try {
            zyInspectionPlanService.queryReportType ( j, req );
        } catch (Exception e) {
            e.printStackTrace ();
            j.setSuccess ( false );
        }
        return j;
    }


    //****二期上线 - 初始化操作(用后可以删除)
    @ResponseBody
    @RequestMapping(params = "cbs2OnLineInitialization")
    public AjaxJson cbs2OnLineInitialization() {
        AjaxJson aj = new AjaxJson ();
        try {
            List<ZyInspectionPlanEntity> doneIps = systemService.findByProperty ( ZyInspectionPlanEntity.class, "state", StaticValue.DIC_PLAN_STATE_INSPECTION_COMPLETE );
            for (ZyInspectionPlanEntity doneIp : doneIps) {
                cbsInspectionEvaluateServiceI.createInspectionEvaluate ( doneIp.getId () );
            }
        } catch (Exception e) {
            e.printStackTrace ();
            aj.setSuccess ( false );
            aj.setMsg ( "初始化失败了" );
        }
        return aj;
    }


}

